我有一个包含3个标签的电子表格。我需要以下代码来选择前两个选项卡。我几乎拥有它,但Sheets(Array(c)).Select
部分返回错误。基本上我需要最后一部分作为表格返回(数组(“Sheet1”,“Sheet2”))。选择
Sub HideUnhide2()
Dim a As String
Dim b As Double
Dim c As String
Application.Calculation = xlManual
For I = 1 To 100
If Range("d5") <> "Entity:" Then Exit For
'Start
c = c & ", " & Chr(34) & ActiveSheet.Name & Chr(34)
'End
b = b + 1
ActiveSheet.Next.Select
Next I
' End If
c = Right(c, Len(c) - 2)
MsgBox c
Sheets(Array(c)).Select
Application.Calculation = xlAutomatic
MsgBox "Total tabs updated = " & b
End Sub
感谢任何帮助。
答案 0 :(得分:1)
这个怎么样?
Sub SelectTabs()
Dim numSheets As Integer
numSheets = 5
Dim aSheets() As String
ReDim aSheets(numSheets - 1)
For i = 0 To numSheets - 1
aSheets(i) = ActiveWorkbook.Worksheets(i + 1).Name
Next i
ActiveWorkbook.Worksheets(aSheets()).Select
End Sub
答案 1 :(得分:0)
Worksheet.Select
Method可让您指定是否要添加或替换当前选择:
Dim ws as Worksheet, replaceSelection As Boolean
replaceSelection = True
For Each ws In ThisWorkbook.Worksheets
If ws.Range("d5") = "Entity:" Then
ws.Select Replace:=replaceSelection
replaceSelection = False
End If
Next
从当前工作表开始选择:
Dim ws as Worksheet, replaceSelection As Boolean
replaceSelection = True
While Not ws Is Nothing
If ws.Range("d5") = "Entity:" Then
ws.Select Replace:=replaceSelection
replaceSelection = False
End If
Set ws = ws.Next
Wend