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

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
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 :biggrin:
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,551
Members
449,088
Latest member
davidcom

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