Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50067

Hide Columns Containing "0" Values

$
0
0
Hello,

I would like my macro to hide rows and columns containing "0" values. The code to hide the rows works, but the code to hide the columns does not. Here is my code:

The code marked with the red text creates a runtime error '1004'.

Code:

Sub HideRows()

''Here the rows 3007-3028 are checked.
''This code works.
'
'Dim i As Integer
'i = 3007
'Do While Not Cells(i, 6) = Cells(3029, 6)
'
'    If Cells(i, 6).Value = 0 Then
'        Rows(CStr(i) + ":" + CStr(i)).EntireRow.Hidden = True
'    ElseIf Cells(i, 6).Value <> 0 And Rows(CStr(i) + ":" + CStr(i)).EntireRow.Hidden = True Then
'        Rows(CStr(i) + ":" + CStr(i)).EntireRow.Hidden = False
'    End If
'i = i + 1
'Loop


'Here the columns G-AX are checked.
' This code does not work!
Dim j As Integer
j = 7
Do While Not Cells(3004, j) = Cells(3004, 51)

    If Cells(3004, j).Value = 0 Then
        Columns(CStr(j) + ":" + CStr(j)).EntireColumn.Hidden = True
    ElseIf Cells(3004, j).Value <> 0 And Columns(CStr(j) + ":" + CStr(j)).EntireColumn.Hidden = True Then
        Columns(CStr(j) + ":" + CStr(j)).EntireColumn.Hidden = False
    End If
j = j + 1
Loop
End Sub

Thank you for your help!

~az!

Viewing all articles
Browse latest Browse all 50067

Trending Articles