Solved

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

Posted on 2014-11-26
4
131 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 500 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 47

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

733 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