我正在创建一个程序,从sheet1宏中的多个工作表中提取数据。我已经创建了一个子函数和一个函数(显然返回数据)。我的宏调用函数来获取一些数据,而函数从sheet2中提取数据。我只是VBA编程的初学者,我希望我已经了解了我的意思。
这就是我在做的事情:
Sub foo()
Dim data as String
Dim row As Integer ' for rows increment
row = 1
Sheets("sheet1").Range("A1").Active
Do Until IsEmpty(ActiveCell)
' some code
data = call_from_foo(Cells(row, "A"))
row = row + 1
ActiveCell.Offset(1, 0).Select
Loop
End Sub
Public Function call_from_foo(ByVal com As String) As String
Sheets("Sheet2").Activate
Sheets("Sheet2").Range("D1").Select
Dim row As Integer
row = 2
Do Until IsEmpty(ActiveCell)
' some code here
call_from_foo = Cells(row, "D").Value
row = row + 1
ActiveCell.Offset(1, 0).Select
Loop
End Function
但我收到此错误:
run time error 438: object doesn't support this property or method