VBA: get userform information in the right cells

Mr.Magic

New Member
Joined
May 4, 2011
Messages
9
Hi all!

I have a question related to a macro.

What do i want: if someone enters data in a userform, this information should be inserted in a worksheet. In this worksheet, D2, D3 and D4 are filled with text. The data inserted in the userform should come in E2, E3 and E4, the next time the inserted information should come next to this, (so F2, F3 and F4), the next time, in the column next to it...


Some codes I have found but which are not working:

Code to go to the cell right to the last one used (works):
Range("IV2").End(xlToLeft).Offset(0, 1).Select

Code I tried, but the information inserted gets in the wrong columns:
emptyColumn = WorksheetFunction.CountA(Range("7:7"))
Cells(2, emptyColumn).Value = TextBox1.Value
Cells(3, emptyColumn).Value = TextBox2.Value
Cells(4, emptyColumn).Value = TextBox3.Value

Something automatic I found but not working:
Dim rNextCl As Range
Set rNextC = ActiveSheet.Range("av1").End(xlToLeft).Offset(0, 1)
rNextCl.Value = Me.TextBox1.Value
rNextCl.Offset(1, 0).Value = Me.TextBox2.Value
rNextCl.Offset(1, 0).Value = Me.TextBox3.Value


Thanks a lot for helping me out!!!
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
This should work for you [assuming you have something in cell D2]:

Code:
Private Sub CommandButton1_Click()
Dim rNextCl As Range
    Set rNextCl = ActiveSheet.Range("AV2").End(xlToLeft).Offset(0, 1)
    rNextCl.Value = Me.TextBox1.Value
    rNextCl.Offset(1, 0).Value = Me.TextBox2.Value
    rNextCl.Offset(2, 0).Value = Me.TextBox3.Value
End Sub
 
Upvote 0
At the moment, my excel changed...

I have something in cells E2, E3 and E4, now the information should come next to it... so to column F....
(there is also text in K2, K3 and K4..)

How should I shange the code?
thanks a lot!
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,729
Members
452,939
Latest member
WCrawford

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