Thread: combobox cases
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default combobox cases

Hello

Use the Change Event of the ComboBox and the Select Case
Statement as in the example below

Private Sub ComboBox1_Change()
Dim SelectVal
SelectVal = ComboBox1.Value
Select Case SelectVal
Case 1
Worksheets("Sheet2").Range("B45:B52").Copy
Destination:=Worksheets("Sheet2").Range("B58:B65")
Range("A1").Value = "Number 1 selected"
Case 2
Worksheets("Sheet2").Range("C45:C52").Copy
Destination:=Worksheets("Sheet2").Range("B58:B65")
Range("A1").Value = "Number two chosen"
Case Else
Range("A1").Value = "Numbers 1 and 2 not selected"
End Select
End Sub

Best of luck
Peter Scott

-----Original Message-----
Hello!

I am using excel and combobox to give alternatives for

user.
How to programme following command in VBA:

If comboboxselection = 1 Then
Copy from 'sheet2'!B45:B52 & paste to 'sheet2'!B58:B65

If comboboxselection = 2 Then
Copy from 'sheet2'!C45:B52 & paste to 'sheet2'!B58:B65

If comboboxselection = 3 Then
Copy from 'sheet'!D45:D52 & paste to 'sheet2'!B52:B65
..
..
..
repeated sufficient times...

Hannu Rantala
.