Using Listbox selection to name worksheet

paulsolar

Well-known Member
Joined
Aug 21, 2013
Messages
684
Office Version
  1. 365
Hi All

I'm hoping this is simple. I have a userform that I want to copy data from to two worksheets.

The first worksheet if fixes, the second worksheet is chosen from a userform list box selection. The listbox is populated with the names of the worksheets automatically so I know the sheet names are correct.

Below is the code I'm trying to use. Any ideas on how i name the second worksheet would be greatly appreciated.

Cheers

Paul

Code:
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False


 Dim LastRow As Long, ws As Worksheet


    Set ws = Sheets("Register")


    LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row + 1


    ws.Range("A" & LastRow).Value = TextBox1.Text
    ws.Range("B" & LastRow).Value = TextBox2.Text
    ws.Range("C" & LastRow).Value = TextBox3.Text
    ws.Range("D" & LastRow).Value = TextBox4.Text
    ws.Range("E" & LastRow).Value = TextBox5.Text
    ws.Range("F" & LastRow).Value = TextBox6.Text
    ws.Range("G" & LastRow).Value = TextBox7.Text
    ws.Range("H" & LastRow).Value = TextBox8.Text
    ws.Range("I" & LastRow).Value = TextBox9.Text
    
 Dim LastRow1 As Long, ws1 As Worksheet


    Set ws1 = Sheets(???ListBox1.Value???)


    LastRow1 = ws1.Range("A" & Rows.Count).End(xlUp).Row + 1
    
    ws.Range("A" & LastRow1).Value = TextBox1.Text
    ws.Range("B" & LastRow1).Value = TextBox2.Text
    ws.Range("C" & LastRow1).Value = TextBox3.Text
    ws.Range("D" & LastRow1).Value = TextBox4.Text
    ws.Range("E" & LastRow1).Value = TextBox5.Text
    ws.Range("F" & LastRow1).Value = TextBox6.Text
    ws.Range("G" & LastRow1).Value = TextBox7.Text
    ws.Range("H" & LastRow1).Value = TextBox8.Text
    ws.Range("I" & LastRow1).Value = TextBox9.Text
    


Application.ScreenUpdating = True
End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Sorry all, my bad i just spotted the error

the second sheet i used ws instead of ws1

silly boy
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,893
Members
449,097
Latest member
dbomb1414

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