0

このHideEmptyColumns()マクロは、データがないすべての列を非表示にします。ヘッダー行(行1)を無視するように変更するにはどうすればよいですか?

Sub HideEmptyColumns()
  Dim Col As Range
  For Each Col In ActiveSheet.UsedRange.Columns
     Col.EntireColumn.Hidden = RangeIsEmpty(Col)
  Next Col
End Sub

Function RangeIsEmpty(R As Range) As Boolean
  Dim Cell As Range
  RangeIsEmpty = True
  For Each Cell In R.Cells
     If Cell.Value <> "" Then
        RangeIsEmpty = False
        Exit For
     End If
  Next Cell
End Function
4

1 に答える 1

3

どの行にあるかを確認してください

Sub HideEmptyColumns()
  Dim Col As Range
  For Each Col In ActiveSheet.UsedRange.Columns
     Col.EntireColumn.Hidden = RangeIsEmpty(Col)
  Next Col
End Sub

Function RangeIsEmpty(R As Range) As Boolean
  Dim Cell As Range
  RangeIsEmpty = True
  For Each Cell In R.Cells
     'are we not on the first row (header row)
     If Cell.Row <> 1 Then
        If Cell.Value <> "" Then
           RangeIsEmpty = False
           Exit For
        End If
     End If
  Next Cell
End Function
于 2012-12-11T23:40:12.053 に答える