VBA to hide 3 columns hides all of them instead

rickles1

New Member
Joined
Jan 2, 2012
Messages
2
Hi everyone, this is my first post here so I hope you can help :)
Here is the code I have so far:

Sub Update()
Columns("H:J").Select
Selection.EntireColumn.Hidden = False
Range("H7").Select
Selection.AutoFill Destination:=Range("H7:H306"), Type:=xlFillDefault
Range("I7").Select
Selection.AutoFill Destination:=Range("I7:I306"), Type:=xlFillDefault
Range("J7").Select
Selection.AutoFill Destination:=Range("J7:J306"), Type:=xlFillDefault
Range("B7:B9").Select
Selection.AutoFill Destination:=Range("B7:B306"), Type:=xlFillDefault
Columns("H:J").Select
Selection.EntireColumn.Hidden = True
Range("A1").Select
End Sub

At the end when I want columns H:J to be hidden, it does not do this. I have this macro on a button, and when I click on the button it hides columns B:J instead. Then I have to manually unhide these columns that I don't want to be hidden (B:G) otherwise I can't see anything. Can anyone see where I am going wrong?
Also, I have Excel 2007 but I have made this worksheet into the 2003 version because it is for my friend who only has Excel 2003.
Any help would be much appreciated. Many thanks :)
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Hi and welcome.

You don't need to unhide and select cells to autofill. I think this would do the same thing.

Code:
Sub Update()
    
    Range("H7:J7").AutoFill Destination:=Range("H7:J306"), Type:=xlFillDefault
    
    Range("B7:B9").AutoFill Destination:=Range("B7:B306"), Type:=xlFillDefault

End Sub
 
Upvote 0
Ahh thanks very much AlphaFrog! Works perfectly, a lot easier than hiding and unhiding the columns haha :-D
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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