Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default combobox cases

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default combobox cases

use a case statement in the click event

Private Sub Combobox1_Click()
Case Combobox1.ListIndex + 1
Case 1
Range("Sheet2!B45:B52").Copy Destination:=Range("Sheet2!B59")
Case 2
Range("Sheet2!C45:C52").Copy Destination:=Range("Sheet2!B59")
Case 3
Range("Sheet2!D45:D52").Copy Destination:=Range("Sheet2!B59")
Case . . .
End Select
End sub

if the column just shifts over 1 you could use

Private Sub Combobox1_Click()
Dim rng as Range
set rng = Range("Sheet2!B45:B52")
rng.offset(0,combobox1.ListIndex).Copy _
Destination:=Range("Sheet2!B59")
End Sub

--
Regards,
Tom Ogilvy

"Hannu Rantala" wrote in message
om...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default combobox cases

Hi Hannu,

With Worksheets("Sheet2")
If Combobox1.ListIndex = 0 Then
.Range("B45:B52 ").Copy Destination:=.Range("B58")
ElseIf Combobox1.ListIndex = 1 Then
.Range("C45:C52 ").Copy Destination:=.Range("B58")
ElseIf Combobox1.ListIndex = 2 Then
.Range("D45:D52 ").Copy Destination:=.Range("B58")
End If
End With

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Hannu Rantala" wrote in message
om...
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



  #4   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
.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default combobox cases

Thank you Bob. The program works excellent!


"Bob Phillips" wrote in message ...
Hi Hannu,

With Worksheets("Sheet2")
If Combobox1.ListIndex = 0 Then
.Range("B45:B52 ").Copy Destination:=.Range("B58")
ElseIf Combobox1.ListIndex = 1 Then
.Range("C45:C52 ").Copy Destination:=.Range("B58")
ElseIf Combobox1.ListIndex = 2 Then
.Range("D45:D52 ").Copy Destination:=.Range("B58")
End If
End With

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Hannu Rantala" wrote in message
om...
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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formula for Cases=144 * # of Cases + Pieces Inventory Formula Excel Discussion (Misc queries) 2 December 29th 09 09:09 PM
fill combobox depending on selection from another combobox Adam Francis Excel Discussion (Misc queries) 2 July 24th 08 07:39 PM
repetition cases Omar Excel Discussion (Misc queries) 2 May 9th 07 09:17 PM
two cases for countif joi2 Excel Worksheet Functions 1 November 8th 05 02:07 PM
Matching 2 cases at once. mae1778 Excel Discussion (Misc queries) 2 August 26th 05 09:50 PM


All times are GMT +1. The time now is 07:00 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"