VBA error copying userform textbox data to a worksheet

slinney

New Member
Joined
Nov 13, 2015
Messages
2
Am desperately trying to get the below code working (I'm very new to VBA). I basically have a userform with textboxes and a cmd button. The userform opens in one worksheet and I want to paste the data to the last row of a customer list in a different worksheet. The bug starts at the line: emptyRow=Sheet8.Cells(Rows.Count,1).End(x1Up).Offset(1,0).Row
There will be times when only some of the textboxes will be completed. Really appreciate advice

Private Sub cmdAddCustomerData_Click()

Sheets("Cust Details").Select

emptyRow=Sheet8.Cells(Rows.Count,1).End(x1Up).Offset(1,0).Row
Cells(emptyRow,4)=TextboxCustName.Text
Cells(emptyRow,8)=TextboxStreet1.Text
Cells(emptyRow,9)=TextboxStreet2.Text
Cells(emptyRow,10)=TextboxTown.Text
Cells(emptyRow,11)=TextboxCounty.Text
Cells(emptyRow,12)=TextboxPostCode.Text
Cells(emptyRow,13)=TextboxContactName.Text
Cells(emptyRow,14)=TextboxTel.Text
Cells(emptyRow,15)=TextboxFax.Text
Cells(emptyRow,102)=TextboxInstructions.Text
Cells(emptyRow,109)=ComboBoxTradeTerms.Text
Cells(emptyRow,110)=ComboBoxPayMethod.Text
Cells(emptyRow,112)= ComboBoxPrintInv.Text
Cells(emptyRow,113)= ComboBoxPrintDelNote.Text
Cells(emptyRow,114)=TextboxEmail.Text

Sheets("Inputs").Select
End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hi Slinney,

try this

Code:
dim ws as worksheet

set ws = workbooks("Your Workbook").sheets("Cust Details")

EmptyRow = ws.Cells.Find(What:="*", searchOrder:=xlRows, searchdirection:=xlPrevious, _
    LookIn:=xlValues).Row +1

then the rest of your code.

Greg
 
Upvote 0
Greg, you're an absolute hero, I have spent all day on this. Thank you very much, really appreciated
 
Upvote 0

Forum statistics

Threads
1,215,639
Messages
6,125,968
Members
449,276
Latest member
surendra75

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