Adding userform data to two different sheets

rickblunt

Well-known Member
Joined
Feb 18, 2008
Messages
609
Office Version
  1. 2019
Platform
  1. Windows
Greetings, I have been using this userform and code for several months without issue, but today I added a couple of textboxes to my userform to pass data to a different sheet; and now I am having issues with the new textboxes. The original code passed the userform data to one sheet -"wafer counts"; but these new boxes are sending data to a different sheet - "Gas Delivery Data". The quirk is that on the first sheet everything was just going into the next blank row so it is very simple. But on the second sheet it is going into cells that are not on the first blank row, there will be data on many of the cells on that same row. So I need to pass the value to the first blank cell in that particular column. I am getting a runtime error on the new code that I added, not sure if I got my syntax wrong or if the way that I did it is totally wrong to begin with. Could anyone offer me any comments on where I am getting this wrong? Thanks - Rick




Code:
Private Sub EnterButton1_Click()
    Dim NextRow As Long
    Dim NextEmptyRow As Long
    
'   Make Sure Wafer Counts is Active
    Sheets("Wafer Counts").Activate
    
'   Determine the next empty row
    NextRow = Application.WorksheetFunction. _
        CountA(Range("C:C")) + 2
        
'   Transfer the Date
    Cells(NextRow, 1) = TextDate1.Text
    
'   Transfer the Name
    Cells(NextRow, 2) = TextName1.Text
    
' Transfer all of the userform data
 
    Cells(NextRow, 3) = TextBox1.Text
    Cells(NextRow, 4) = TextBox53.Text
    Cells(NextRow, 5) = TextBox54.Text
    Cells(NextRow, 6) = TextBox55.Text
    Cells(NextRow, 7) = TextBox57.Text
   'a bunch of other userform stuff....
    
   
' Need to add additional information to a different sheet so make sure Gas Delivery Data is active.
    Sheets("Gas Delivery Data").Activate
   
[I]'Here is where I am getting my runtime error.... [/I]
    NextEmptyRow = Sheets("Gas Delivery Data").Cells(Rows.Count, AO).End(xlUp).Offset(1).Row
        Sheets("Gas Delivery Data").Cells(NextEmptyRow, "AO").Value = TextBox105.Text

    NextEmptyRow = Sheets("Gas Delivery Data").Cells(Rows.Count, AQ).End(xlUp).Offset(1).Row
        Sheets("Gas Delivery Data").Cells(NextEmptyRow, "AQ").Value = TextBox106.Text
 
    Unload UserForm2
     
End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Rick

I am not sure what you are trying to do with the AO and AQ, but you are inconsistent with the "". If you are getting the next empty row in columns AO or AQ you will probably be better off with 41 or 43.

Code:
NextEmptyRow = Sheets("Gas Delivery Data").Cells(Rows.Count, 41).End(xlUp).Offset(1).Row

I hope this helps.

Ken
 
Upvote 0
Thanks Ken that got it - I had originally done the numbers, but that didn't work so I went to the letters; but it still didn't work - probably because of those "" that didn't need to be there = doh! Working fine now - thanks for the second set of eyes.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,190
Members
452,616
Latest member
intern444

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