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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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
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,215,551
Messages
6,125,478
Members
449,233
Latest member
Deardevil

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