0

**これは、これらの名前(sht1-sht9)で除外されたsheetNamesを列Mに提供するためのコードです::

Public Sub Worksheet_Activate() Const sht1 As String = "Main-test" Const sht2 As String = "Data-list" Const sht3 As String = "Report" Const sht4 As String = "EmpList" Const sht5 As String = "emp_intface" Const sht6 As String = "sample" Const sht7 As String = "SSSSSS" Const sht8 As String = "log" Const sht9 As String = "Report2" Range("m:m").ClearContents Dim S As Integer For S = 1 To Worksheets.Count With Worksheets("Report2") Set ws = Worksheets(S) If ws.Visible = True And _ (ws.Name <> sht1) And (ws.Name <> sht2) And (ws.Name <> sht3) And (ws.Name <> sht5) And _ (ws.Name <> sht4) And (ws.Name <> sht6) And (ws.Name <> sht7) And (ws.Name <> sht8) _ And (ws.Name <> sht9) Then .Cells(S, 13).Value = ws.Name End If End With Next End Sub

* *私の問題を説明するための詳細:

したがって、これらの除外されたSheetNamesが最初に取得され、残りのシートは除外されたSheetsの後の最後の順序になります。したがって、このコードを実行すると、列Mにいくつかの空白行が作成されます。シートの順序が除外されたため、解決策は何ですか。 SHeetNamesを10行目または11行目から列Mの最初の空白行に移動するには???`

4

1 に答える 1

0

変数を使用しSて行をインクリメントしないでください。そうしないと、IF条件が満たされない場合に空白になります。これを試して

Dim S As Integer, R As Long

R = 1

For S = 1 To Worksheets.Count
    With Worksheets("Report2")
        Set ws = Worksheets(S)
        If ws.Visible = True And (ws.Name <> sht1) And (ws.Name <> sht2) _
        And (ws.Name <> sht3) And (ws.Name <> sht5) And (ws.Name <> sht4) _
        And (ws.Name <> sht6) And (ws.Name <> sht7) And (ws.Name <> sht8) _
        And (ws.Name <> sht9) Then
            .Cells(R, 13).Value = ws.Name
            R = R + 1
        End If
    End With
Next
于 2012-09-04T07:48:58.017 に答える