I'm not sure what are trying to achieve, but above code hasn't got proper context. What it means?
Range Object[
^] represents a cell, a column, a row and selection of cells in currently active Sheet.
Please, do the following:
- Activate
Sheet1
- Go to Code pane (ALT+F11)
- Insert new module
- Copy and paste below code
Sub TestRange()
Range("A1") = "Test no. " & Rand()
End Sub
- Run the code (F5)
- Go to active sheet (
Sheet1
) and check A1 cell value - Now, go to another sheet (
Sheet2
) and run macro again - Check A1 cells in Sheet1 and Sheet2
Conclusion: Write the code on context of usage, for example:
Sheet1.Range("A1") = Rand()
'or (better)
Worksheets("Sheet1").Range("A1") =Rand()
'or (best of)
ThisWorkbook.Worksheets("Sheet1").Range("A1") =Rand()
Let get back to your question...
I would suggest you to write custom function:
Function GetFirstEmptyRow(wsh As Worksheet, Optional sColName as String= "A") As Long
GetFirstEmptyRow = wsh.Range(sColName & wsh.Rows.Count).End(xlUp).Row +1
End Function
Usage:
Dim myWsh as Worksheet
Dim firstEmptyRow As Long
Set myWsh = ThisWorkbook.Worksheets("Sheet1")
firstEmptyRow = GetFirstEmptyRow(myWsh, "L")
myWsh.Range("L" & firstEmptyRow).Select
Set myWsh = Nothing