Fill from first populated cell to top

mucah!t

Well-known Member
Joined
Jun 27, 2009
Messages
593
Hello all,

How do I get the value of a textbox [on a userform] copied from the first populted cell in lets say column "M" till the top of that column.

Actually M1 has a columnhead, so this needs to be ignored when looking for the first populated cell.

Ideas?
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Perhaps like this

Code:
Private Sub CommandButton1_Click()
Dim NR As Long
NR = Range("M1").End(xlDown).Row
Range(Cells(2, 13), Cells(NR - 1, 13)).Value = TextBox1.Text
End Sub
 
Upvote 0
Thank you VoG!
I seems to work just fine.
What do I need to change to apply it to another worksheet.
I tried the following but that does not work:

Code:
Private Sub CommandButton1_Click()
Dim NR As Long
With Worksheets("Database")
NR = Range("M1").End(xlDown).Row
Range(Cells(2, 13), Cells(NR - 1, 13)).Value = TextBox1.Text
End With
End Sub
 
Upvote 0
Try this

Code:
Private Sub CommandButton1_Click()
Dim NR As Long
With Worksheets("Database")
    NR = .Range("M1").End(xlDown).Row
    .Range(.Cells(2, 13), .Cells(NR - 1, 13)).Value = TextBox1.Text
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

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