?
Solved

How can I export data from a VBA Userform to Excel?

Posted on 2014-11-26
4
Medium Priority
?
147 Views
Last Modified: 2014-12-23
I have the following code to export some data values from a Userform to Excel.

Private Sub ExportCommandButton_Click()

'Determine next empty row in the Analysis worksheet
Dim erow As Long
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
erow = ws.Cells(Rows.Count, 1).End(x1Up).Offset(1, 0).Row

'Transfer information from Text and Combo Boxes
ws.Cells(erow, 1) = ItemNumberTextBox.Value
ws.Cells(erow, 2) = cboMachType.Value
ws.Cells(erow, 3) = SetupTimeTextBox.Value
ws.Cells(erow, 4) = CycleTimeTextBox.Value
ws.Cells(erow, 8) = GroupNumberTextBox.Value

'Transfer information from Option Buttons
If MachineStatusOptionButton1 = True Then ws.Cells(erow, 5) = "1"
If MachineStatusOptionButton2 = True Then ws.Cells(erow, 6) = "1"
If MachineStatusOptionButton3 = True Then ws.Cells(erow, 7) = "1"

End Sub

Open in new window


I am getting an "application-defined or Object-defined error" pointing towared this row.
erow = ws.Cells(Rows.Count, 1).End(x1Up).Offset(1, 0).Row

Open in new window


What am I doing wrong?
0
Comment
Question by:Nugget1224
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 2000 total points
ID: 40467005
It's very subtle.

You've got x1Up (X - number 1 - U - P)

Instead, you should have xlUp (X - L - U - P)
0
 

Author Comment

by:Nugget1224
ID: 40467036
Thank you. That is infuriatingly simple.
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 40514585
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question