Run Time Error 1004

RIZVI

Active Member
Joined
Jan 1, 2011
Messages
283
Hi All,

I am getting Run Time Error 1004 on this code

Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
Application.ScreenUpdating = False
For Each c In Range("AG3:AR3,AW3:CF3")
If c.Value = "0" Then
c.EntireColumn.Hidden = True
Else
c.EntireColumn.Hidden = False
End If
Next
Application.ScreenUpdating = False
End Sub

<tbody>
</tbody>



The debugging part that gets yellow is c.EntireColumn.Hidden = False



Can any one help me where things are wrong and what correction is required.


Thanks in anticipation.

Rizvi

<tbody>
</tbody>
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hi,
see if this change to your code helps.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim c As Range
    Application.ScreenUpdating = False
    For Each c In Range("AG3:AR3,AW3:CF3")
            Me.Columns(c.Column).EntireColumn.Hidden = c.Value = "0"
    Next
    Application.ScreenUpdating = True
End Sub

Dave
 
Upvote 0
@RIZVI
The code works fine for me....but I did change the zero to literal rather than text
Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
Application.ScreenUpdating = False
    For Each c In Range("AG3:AR3,AW3:CF3")
        If c.Value = 0 Then
            c.EntireColumn.Hidden = True
            Else
            c.EntireColumn.Hidden = False
        End If
    Next
Application.ScreenUpdating = False
End Sub
 
Upvote 0
ADVERTISEMENT
Is the worksheet protected?
 
Upvote 0
Hi Michael,

Tried the above code also,but the problem remains.

There are other codes also in the sheet. Can that be the reasons?

Need help please.

RGDS,

Rizvi
 
Upvote 0
You can only have the 1 sheet event
 
Upvote 0

Forum statistics

Threads
1,196,134
Messages
6,013,641
Members
441,777
Latest member
Lleuadwen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top