Use result of formula in VBA

tourgis2000

New Member
Joined
Sep 3, 2008
Messages
48
Hi,

Once again I again I find myself fumbling with basic VBA. I need to hide or unhide a number of columns on each worksheet of a file but the number of columns is different on each worksheet. I have a clculation in my spreadsheet as follows:

="B:"&SUBSTITUTE(ADDRESS(10,A1+1,4),"10","")

This might produce the following:

B:F

How can I get this into VBA thus?

Code:
Sub Hide_columns()
    Columns("B:F").Select
    Selection.EntireColumn.Hidden = True
    Range("A1").Select
End Sub
Thanks,

Martin
 
replace K6 with where your formula is.


Code:
Sub Hide_columns()
    
Dim myColumns As String
 
myColumns = Range("K6")
    
Columns(myColumns).EntireColumn.Hidden = True
 
End Sub
 
Last edited:
Upvote 0

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