2017-04-18 96 views
2

我有一個帶有100-150個工作表的工作簿我創建了一個代碼,它將更改除以下名稱的工作表之外的所有工作表的行高和列寬:「Cover」「Trans_Letter 「,」縮寫「和以_Index結尾的工作表名稱。更改列寬和行高

我的代碼工作正常,並且改變了行高和列寬,但是它也改變了以_Index結尾的表名的列寬和行高。

請建議如何修改代碼,以便在循環時跳過以_Index結尾的表名。

我想下面的行需要修改: -

If ShtNames(Z) <> "Trans_Letter" And ShtNames(Z) <> "Cover" And ShtNames(Z) <> "Abbreviations" And InStr("_Index", ShtNames(Z)) = 0 Then 

請找到下面的代碼: -

Sub rowcolallsheetbtransletter() 

    Dim exworkb As Workbook 
    Dim xlwksht As Worksheet 
    Dim lastrow1 As Long 
    Dim lastcolumn1 As Long 
    Dim firstrowDB As Long 
    Dim Z As Integer 
    Dim ShtNames() As String 

    ReDim ShtNames(1 To ActiveWorkbook.Sheets.Count) 

    For Z = 1 To Sheets.Count 

     ShtNames(Z) = Sheets(Z).Name 

     If ShtNames(Z) <> "Trans_Letter" And ShtNames(Z) <> "Cover" And ShtNames(Z) <> "Abbreviations" And InStr("_Index", ShtNames(Z)) = 0 Then 

      Sheets(Z).Select 

      lastrow1 = Sheets(Z).Cells(Rows.Count, "A").End(xlUp).Row 
      lastcolumn1 = Sheets(Z).Cells(1, Columns.Count).End(xlToLeft).Column 

      ActiveWorkbook.Sheets(Z).Range(Sheets(Z).Cells(1, 2), Sheets(Z).Cells(lastrow1, lastcolumn1)).Select 

      Selection.Cells.RowHeight = 67 
      Selection.Cells.ColumnWidth = 30 

     End If 
    Next Z 
End Sub 

回答

1

而不是檢查工作表名稱是否字符串「_index」中存在的,檢查表單名稱中是否存在「_Index」:

If ShtNames(Z) <> "Trans_Letter" And _ 
    ShtNames(Z) <> "Cover" And _ 
    ShtNames(Z) <> "Abbreviations" And _ 
    InStr(ShtNames(Z), "_Index") = 0 Then 
+0

它的工作非常感謝你! – Stacey