Transfer data to worksheet

rharri1972

Board Regular
Joined
Nov 12, 2021
Messages
132
Office Version
  1. 2019
Platform
  1. Windows
Hello!
I have a userform "Cust_Line_Order_Form" with 4 textboxes. Textbox 13,4,&5, and a command button "OK".

When I click the "OK" button I am trying to get the textbox data to worksheet "CUSTOMER ORDER".

The first possible cell is B and row is 12.

B12 (Textbox1), C12(Textbox3), D12 (Textbox4), G12(Textbox5).

I've tried using the .end(xlup) with range ("B12:B") but nothing is happening on the execution of subroutine from button click.

I am using the (xlup) because there may be multiple line items.... each time i hit the ok button i need it to find the next available cell/row to enter the next data starting with B12.

VBA Code:
Private Sub CommandButton1_Click()
Dim lr As Long
lr = Sheets("CUSTOMER ORDER").Cells(Rows.Count, "B").End(xlUp).Row + 1
 
   ActiveCell.Value = Me.TextBox1.Value
  
     ActiveCell.Offset(0, 1).Value = Me.TextBox3.Value
    
        ActiveCell.Offset(0, 2).Value = Me.TextBox4.Value

            ActiveCell.Offset(0, 3).Value = Me.TextBox5.Value
          

End Sub

                        any help will be greatly appreciated!!!
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hi,
try this update to your code & see if does what you want

VBA Code:
Private Sub CommandButton1_Click()
    Dim lr              As Long
    Dim wsCustomerOrder As Worksheet
    
    Set wsCustomerOrder = ThisWorkbook.Worksheets("CUSTOMER ORDER")
    
    With wsCustomerOrder
        lr = .Cells(.Rows.Count, "B").End(xlUp).Row + 1
        If lr < 12 Then lr = 12
        
        .Cells(lr, 2).Value = Me.TextBox1.Value
        .Cells(lr, 3).Value = Me.TextBox3.Value
        .Cells(lr, 4).Value = Me.TextBox4.Value
        .Cells(lr, 7).Value = Me.TextBox5.Value
        
    End With
    
End Sub

Dave
 
Upvote 0
Solution
Hi,
try this update to your code & see if does what you want

VBA Code:
Private Sub CommandButton1_Click()
    Dim lr              As Long
    Dim wsCustomerOrder As Worksheet
   
    Set wsCustomerOrder = ThisWorkbook.Worksheets("CUSTOMER ORDER")
   
    With wsCustomerOrder
        lr = .Cells(.Rows.Count, "B").End(xlUp).Row + 1
        If lr < 12 Then lr = 12
       
        .Cells(lr, 2).Value = Me.TextBox1.Value
        .Cells(lr, 3).Value = Me.TextBox3.Value
        .Cells(lr, 4).Value = Me.TextBox4.Value
        .Cells(lr, 7).Value = Me.TextBox5.Value
       
    End With
   
End Sub

Dave
works great!! I also tried declaring variables... im just not there yet with the knowledge. Long is just to be able to handle more data or find more data right?
 
Upvote 0
The total number of rows on a worksheet versions from 2007 > is 1,048,576
so you declare A Long variable which can store a value up to 2,147,483,64

You may find this helpful:VBA for Beginners: VBA Variables Explained Simply - Online PC Learning
Dave, I have posted this to the site, i wanted to let you know before sending this. I do not know what you guys can do or not do...like rules you may have. However, is it possible to start typing into a textbox and have it immediately start showing the possible matches from a listbox while i am typing? Listbox is on the same userform as the textbox.
 
Upvote 0
simple answer yes but its an unrelated question & should be answered in your other thread

Dave
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,290
Members
452,902
Latest member
Knuddeluff

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