我想使用一個函數,將允許我從以前的工作表中導入一個範圍。我不確定我目前的宏是否允許這樣做。我可以手動調用以前的工作表,但不能使用我擁有的功能。VLookup範圍在另一個工作表動態
這裏是一個正常工作的功能時,我手動輸入工作表名稱:
=IFERROR(VLOOKUP(D3,Aug9Daily!$D$3:$F$50,3, FALSE),"")
這裏是我在嘗試使用的功能:
=IFERROR(VLOOKUP(D3,NextSheetName()$D$3:$F$50,3, FALSE),"")
這是VBA,我我正在使用NextSheetName宏:
Function NextSheetName(Optional WS As Worksheet = Nothing) As String
Application.Volatile True
Dim S As String
Dim Q As String
If IsObject(Application.Caller) = True Then
Set WS = Application.Caller.Worksheet
If WS.Index = WS.Parent.Sheets.Count Then
With Application.Caller.Worksheet.Parent.Worksheets
Set WS = .Item(1)
End With
Else
Set WS = WS.Next
End If
If InStr(1, WS.Name, " ", vbBinaryCompare) > 0 Then
Q = "'"
Else
Q = vbNullString
End If
Else
If WS Is Nothing Then
Set WS = ActiveSheet
End If
If WS.Index = WS.Parent.Worksheets.Count Then
With WS.Parent.Worksheets
Set WS = .Item(1)
End With
Else
Set WS = WS.Next
End If
Q = vbNullString
End If
NextSheetName = Q & WS.Name & Q
End Function
我在做什麼錯?有沒有更好的方法來動態地從另一個工作表中選擇範圍?
您得到了什麼錯誤消息? – PowerUser 2012-08-13 18:27:46
如果我按上面所述輸入它,則表示您鍵入的公式包含錯誤。如果我在引號內輸入範圍,NextSheetName($ D $ 3:$ F $ 50),3,FALSE),我得到一個空白單元格(不應該是空白) – rupes0610 2012-08-13 18:29:58