Вот мой код:
Код: Выделить всё
k = Sheets("Лист3").Index
ReDim arr2(1 To k - 1)
For m = 1 To k - 1
arr2(m) = m
Next
Sheets(arr2).Select
Модератор: Naeel Maqsudov
Код: Выделить всё
k = Sheets("Лист3").Index
ReDim arr2(1 To k - 1)
For m = 1 To k - 1
arr2(m) = m
Next
Sheets(arr2).Select
Код: Выделить всё
Sub test()
k& = Sheets("Лист3").Index
Dim sh As Worksheet, n&
For Each sh In ThisWorkbook.Worksheets
If sh.Visible = xlSheetVisible And sh.Index < k& Then
sh.Select n = 0
n = n + 1
End If
Next sh
End Sub
Код: Выделить всё
Private Sub Test()
With ActiveWorkbook.Worksheets
For iCount& = 1 To .Item("Лист3").Index - 1
If .Item(iCount&).Visible = True _
Then .Item(iCount&).Select False
Next
End With
End Sub
Код: Выделить всё
Sub SelectVisibleSheetsBeforeTheSheet3()
Dim ToBeSelected()
ReDim ToBeSelected(1 To 1) 'Чтобы макрос не зависел от Option Base
For i = 1 To sheets("Лист3").Index - 1
If sheets(i).Visible = xlSheetVisible Then
If Not IsEmpty(ToBeSelected(1)) Then ReDim Preserve ToBeSelected(1 To UBound(ToBeSelected) + 1)
ToBeSelected(UBound(ToBeSelected)) = i
End If
Next
If Not IsEmpty(ToBeSelected(1)) Then
sheets(ToBeSelected).Select
Else
MsgBox "There are no sheets that could be selected"
End If
End Sub
Код: Выделить всё
Private Sub Test()
With ActiveWorkbook.Worksheets
Dim iCount&, flagSVW As Boolean
flagSVW = True
For iCount = 1 To .Item("Лист3").Index - 1
If .Item(iCount).Visible = True Then
.Item(iCount).Select flagSVW
flagSVW = False
End If
Next
End With
End Sub
Код: Выделить всё
Private Sub TestNotTest()
With ActiveWorkbook.Worksheets
Dim iCount&, flagSVW As Boolean
For iCount = 1 To .Item("Лист3").Index - 1
If .Item(iCount).Visible = True Then
.Item(iCount).Select Not flagSVW
flagSVW = True
End If
Next
End With
End Sub
Код: Выделить всё
Private Sub Testv2()
Dim iList As Worksheet, flagSVW As Boolean
Set iList = Worksheets("Лист3").Previous
Do Until iList Is Nothing
If iList.Visible = True Then
iList.Select Not flagSVW
flagSVW = True
End If
Set iList = iList.Previous
Loop
End Sub
Код: Выделить всё
Private Sub Testv3()
Dim iList As Worksheet, flagSVW As Boolean
Set iList = Worksheets(1)
Do Until iList Is Worksheets("Лист3")
If iList.Visible = True Then
iList.Select Not flagSVW
flagSVW = True
End If
Set iList = iList.Next
Loop
End Sub