BILLYBOB1972
New Member
- Joined
- Jan 7, 2016
- Messages
- 24
- Office Version
- 2016
- Platform
- Windows
I am trying to move data from a user form to an excel sheet and the code below does what I need for the first instance. The form may contain up to 100 text boxes txtUnits1, txtUnits2, txtUnits3 etc
What I need to do is for every text box move the corresponding data. If there isn't any values in the text box nothing gets moved.
I could copy the code below and change values but have been reading about loops but as I'm new to this I don't know where to start.
Can anyone help point me in the right direction to move the same data for txtUnits2 etc
Dim ws As Worksheet
Dim Addto As Range
Set ws = Sheet2
Set Addto = ws.Range("c65356").End(xlUp).Offset(1, 0)
With ws
If txtUnits1.Value > 0 Then Addto = txtName.Value
If txtUnits1.Value > 0 Then Addtffset(0, 1).Value = cboStore.Value
If txtUnits1.Value > 0 Then Addtffset(0, 2).Value = txtProduct.Value
If txtUnits1.Value > 0 Then Addtffset(0, 4).Value = txtUnits1.Value
What I need to do is for every text box move the corresponding data. If there isn't any values in the text box nothing gets moved.
I could copy the code below and change values but have been reading about loops but as I'm new to this I don't know where to start.
Can anyone help point me in the right direction to move the same data for txtUnits2 etc
Dim ws As Worksheet
Dim Addto As Range
Set ws = Sheet2
Set Addto = ws.Range("c65356").End(xlUp).Offset(1, 0)
With ws
If txtUnits1.Value > 0 Then Addto = txtName.Value
If txtUnits1.Value > 0 Then Addtffset(0, 1).Value = cboStore.Value
If txtUnits1.Value > 0 Then Addtffset(0, 2).Value = txtProduct.Value
If txtUnits1.Value > 0 Then Addtffset(0, 4).Value = txtUnits1.Value