代理不同的表格

时间:2013-11-13 03:00:08

标签: excel excel-vba button vba

我在名为“INPUT”的工作表中有一个按钮。但是,当我单击该按钮时,代码应该对位于名为“SUMBER”的不同工作表中的数据起作用。我该怎么做?

Dim osh As Worksheet
Dim iRow As Long
Dim iCol As Long
Dim iFirstRow As Long
Dim iTotalRows As Long
Dim iStartRow As Long
Dim iStopRow As Long
Dim sSectionName As String
Dim rCell As Range
Dim owb As Workbook
Dim sFilePath As String
Dim iCount As Integer
Dim Response As Integer
Dim sFName As String

iCol = Worksheets("input").Range("B4")
iRow = Worksheets("input").Range("B5")
iFirstRow = iRow

Set osh = Application.ActiveSheet
Set owb = Application.ActiveWorkbook
iTotalRows = osh.UsedRange.Rows.Count
sFilePath = Application.ActiveWorkbook.Path

我一直试图改变这些界限:

Set osh = Application.ActiveSheet
Set owb = Application.ActiveWorkbook

但它没有用。

1 个答案:

答案 0 :(得分:0)

声明并设置工作簿和您的工作表:

Dim owb as Workbook
Dim oshInput, oshSumber as Worksheet

Set owb = Thisworkbook
Set oshInput = owb.Sheets("Input")
Set oshSumber = owb.Sheets("Sumber")

然后添加你想要做的事 例如你的行:

iCol = Worksheets("input").Range("B4")
iRow = Worksheets("input").Range("B5")

完成上述声明后,设置为:

iCol = oshInput.Range("B4")
iRow = oshInput.Range("B5")

希望这有所帮助,让你开始了一点。