View Single Post
  #5   Report Post  
G_Chem
 
Posts: n/a
Default


mangesh_yadav Wrote:
Since you had mentioned a drop down list, I used the combo-box, but if
you want to use the list box instead, heres the code:


Private Sub ListBox1_Click()

Worksheets("Sheet2").Columns("B:D").EntireColumn.H idden = False

If ListBox1.Value = "test1" Then
Worksheets("Sheet2").Columns("B:B").EntireColumn.H idden = True
ElseIf ListBox1.Value = "test2" Then
Worksheets("Sheet2").Columns("C:C").EntireColumn.H idden = True
Else
Worksheets("Sheet2").Columns("D:D").EntireColumn.H idden = True
End If

End Sub



Mangesh



Mangesh you've been a great help but I'm a bit stuck at the moment,
below is my code: this is returning a variable undefined message for
ListBox1.

I seem to be having a problem getting VBA to recognise my listbox.

The ListBox was created in excel using Data ValidationAllow:List,
then my 4 test types values were selected from A34:A37, repectively, to
display the drop down list in A2.

The worksheet is called Trial and the test types are

Alpha (I want this to hide columns K and X to AD)
Beta (I want this to hide columns D, K and L)
Alpha Infinite Depth (I want this to hide columns X to AD)
Beta Infinite Depth (I want this to hide columns D and L)

========================================
Sub ListBox1_Click()

Worksheets("Trial").Columns("A:AD").EntireColumn.H idden = False

If ListBox1.Value = "Alpha" Then
Worksheets("Trial").Columns("K:K,X:AD").EntireColu mn.Hidden = True
ElseIf ListBox1.Value = "Beta" Then
Worksheets("Trial").Columns("D:D,K:L").EntireColum n.Hidden = True
ElseIf ListBox1.Value = "Alpha Infinite Depth" Then
Worksheets("Trial").Columns("X:AD").EntireColumn.H idden = True
ElseIf ListBox1.Value = "Beta Infinite Depth" Then
Worksheets("Trial").Columns("D:D,L:L").EntireColum n.Hidden = True
End If
End Sub
=========================================

I'm really unsure as to how to get VBA to associate the listbox in my
spreadsheet with the commands in the macro

TIA

G_Chem


--
G_Chem
------------------------------------------------------------------------
G_Chem's Profile: http://www.excelforum.com/member.php...o&userid=24366
View this thread: http://www.excelforum.com/showthread...hreadid=379611