Help with R1C1 and ranges in a loop

nikkinickyniki

New Member
Joined
Mar 21, 2014
Messages
2
Hi all,

I'm trying to go through a list on sheet3 which is populated with only true or false, then using this I want to hide or unhide the corresponding columns using R1C1 notation in sheet1. I'm fairly new to vba and not sure what is wrong with my code. I get an "application-defined or object-defined error".

Also I'm using excel 2010.
Here is my code.

Sub hide_columns()

Dim x As Integer
Dim y As String

For x = 1 To 17


Worksheets("Sheet1").Range(Cells(1, x)).EntireColumn.Hidden = Worksheets("Sheet3").Range(Cells(x, 2)).Value

Next x


End Sub

Any help will be appreciated. Thanks.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Try

Code:
Worksheets("Sheet1").Cells(1, x).EntireColumn.Hidden = Worksheets("Sheet3").Cells(x, 2).Value
 
Upvote 0

Forum statistics

Threads
1,223,108
Messages
6,170,140
Members
452,304
Latest member
Thelingly95

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