2017-04-18 88 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