Solved

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

Posted on 2014-11-26
4
115 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
4 Comments
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 500 total points
Comment Utility
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
Comment Utility
Thank you. That is infuriatingly simple.
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
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.

771 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now