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.
 
Your question relates to the code provided by @shg

With ... requires End With

Code:
Sheets("Outgoings").Range("B2:F2")
is the same as (note the .)
Code:
With Sheets("Outgoings")
    [COLOR=#0000cd].[/COLOR]Range("B2:F2")
End With

Code:
Private Sub CommandButton2_Click()
[COLOR=#0000cd]With[/COLOR] Sheets("Outgoings")
  Select Case ComboBox1.Value
    Case "Energy Supplier"
        [SIZE=4][COLOR=#0000cd].[/COLOR][/SIZE]Range("B2:F2").Value = Array(ComboBox1.Value, TextBox1.Value, TextBox2.Value, _
                                   TextBox3.Value, TextBox4.Value, TextBox5.Value)
    Case "Phone Supplier"
        [SIZE=4][COLOR=#0000cd].[/COLOR][/SIZE]Range("B3:F3").Value = Array(ComboBox1.Value, TextBox1.Value, TextBox2.Value, _
                                   TextBox3.Value, TextBox4.Value, TextBox5.Value)
    Case "Broadband Supplier"
            ' [COLOR=#ff0000][I]add the rest yourself [/I][/COLOR]- which range applies to Broadband Supplier? 
  End Select
[COLOR=#0000cd]End With[/COLOR]
  ActiveWorkbook.Save
End Sub
 
Last edited:
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,214,591
Messages
6,120,426
Members
448,961
Latest member
nzskater

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