Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Select multiple columns to excel VBA

Private Sub ShowHideWST_Click()
Dim MyC As String
MyC = "G:I" And "T:W"
If ShowHideWST.Value Then
Application.ActiveSheet.Columns(MyC).Hidden = True
Else
Application.ActiveSheet.Columns(MyC).Hidden = False
End If
End Sub

I want to select multiple column in excel VBA. MyC = "G:I And "T:W" is clearly giving error. Please guide me how to select multiple columns

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This should work, access the range first then to its Columns property to set the Hidden property, the code can be shorten as well since you are setting the Hidden value to be the same as ShowHideWST.Value:

Private Sub ShowHideWST_Click()
    Const MyC As String = "G:I,T:W"
    
    ActiveSheet.Range(MyC).Columns.Hidden = ShowHideWST.Value
End Sub
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading