Show exactly one column based on user input

mathsbeauty

Board Regular
Joined
Apr 23, 2011
Messages
89
There is a drop down list from D to AG in VBA user form. The user selects any column from D to AG in the form. I am looking for a simple VBA code to show exactly one column from D to AG (which user have selected) and hide all columns between D to AG. All other columns (not in between D and AG) remain unaffected.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Let's assume that user has selected column "AC"
Try
VBA Code:
Sub ShowOneCol()
  Application.ScreenUpdating = False
  Columns("D:AG").Hidden = True
  Columns("AC").Hidden = False
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
try this for Userform Dropdown. this will require user use the dropdown click on button

Private Sub CommandButton1_Click()
Dim Clm As String
Clm = ComboBox1.Value
ActiveSheet.Range("D:AC").EntireColumn.Hidden = True
ActiveSheet.Cells(, Clm).EntireColumn.Hidden = False
Unload Me
End Sub
 
Upvote 0
I'm confused did you want the user to select from the dropdown or just always Hide the Column "AC"? if I'm not mistaken the Code posted by Peter post 4 will always hide Column "AC"
 
Upvote 0

Forum statistics

Threads
1,215,491
Messages
6,125,101
Members
449,205
Latest member
ralemanygarcia

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