Coding my CommandButton to select data

Big Lar

Well-known Member
Joined
May 19, 2002
Messages
557
WS(COURSE)<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
A1:A6 contains data (a list of names)<o:p></o:p>
B6:T9 is related data for A1<o:p></o:p>
B11:T14 is related data for A2<o:p></o:p>
B16:T19 is related data for A3<o:p></o:p>
Etc…<o:p></o:p>
<o:p></o:p>
My UserForm includes a ComboxBox populated with the data from A1:A6<o:p></o:p>
<o:p></o:p>
I am attempting (without success) to code UserForm's CommandButton1 to select the related data and copy it to B1:T4.

Greatly appreciate any help

<o:p></o:p>
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Not tested, but try on a copy of your workbook;
Code:
Select Case ComboBox1.Value
Case Is = A1
    Range("B6:T9").Select
    Selection.Copy
    Range("B1").Select
    ActiveSheet.Paste
Case Is = A2
    Range("B11:T14").Select
    Selection.Copy
    Range("B1").Select
    ActiveSheet.Paste
Case Is = A3
    Range("B16:T19").Select
    Selection.Copy
    Range("B1").Select
    ActiveSheet.Paste
Case Is = A4
    Range("Your Range").Select
    Selection.Copy
    Range("B1").Select
    ActiveSheet.Paste
    
Case Else
    
    
End Select

HTH
Colin
 
Upvote 0
Is it always 4 rows of data separated by 2 rows?
Code:
Option Explicit
 
Private Sub CommandButton1_Click()
Dim rngSrc As Range
        
    If ComboBox1.ListIndex <> -1 Then
              Set rngSrc = Range("B4:T7").Offset(5 * ComboBox1.ListIndex + 2)
              rngSrc.Copy Range("B2")
    End If
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,559
Messages
6,179,517
Members
452,921
Latest member
BBQKING

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