Command button naked range to copy into specific range

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,227
Office Version
  1. 2010
Platform
  1. Windows
Hi please can you help I have a command button1 with s list for example: shop, car, home. If home is selected then what I type into the text box I want this copied into sheet2 A2:A5. If car is selected I want the text in the textbox copied into sheet2 B2:B5 hope this makes sense please can you help? I have a button called update where I want the code to go.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try something like this
Code:
Private Sub CommandButton1_Click()
    Dim c As String
    Select Case ComboBox1.Value
        Case "car":     c = "B"
        Case "home":    c = "A"
        Case "shop":    c = "C"
        Case Else:      Exit Sub        'prevents code crashing if nothing selected
    End Select

    Sheets("Sheet2").Cells(2, c).Resize(4) = TextBox1.Value
End Sub
 
Upvote 0
Hi this is great thank you. How can i add data fro. More than 1 text box? For example if I have textbox1, textbox2 and textbox3? And want to copy that data over. Thanks so much for your time and help.
 
Upvote 0
Which cell is getting Textbox1 value ?
Which cell is getting Textbox2 value ?
Which cell is getting Textbox3 value ?
 
Upvote 0
If you do not tell me where to put the values I cannot help you
 
Upvote 0
Ow sorry. For example if car selected then I want text box 1,2 and 3 to go into row b
 
Upvote 0
Last try
Where is row B?

Columns A B C ..
Rows are 1, 2 ,3 ..
 
Last edited:
Upvote 0
Hi yes sorry it will he like textbox1 into B1. Textbox2 into B2 and textbox3 into B3 for example
 
Upvote 0
Is this what you want?

Code:
Private Sub CommandButton1_Click()
    Dim c As String
    Select Case ComboBox1.Value
        Case "car":     c = "B"
        Case "home":    c = "A"
        Case "shop":    c = "C"
        Case Else:      Exit Sub        'prevents code crashing if nothing selected
    End Select
    With Sheets("Sheet2")
        .Cells(1, c) = TextBox1.Value
        .Cells(2, c) = TextBox2.Value
        .Cells(3, c) = TextBox3.Value
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,552
Messages
6,120,172
Members
448,948
Latest member
spamiki

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