Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Dim LastRow As Long, AddText As Long, SelectText As String
LastRowL = Range("L65536").End(xlUp).Row
AddText = LastRowL + 1
SelectText = "L" & AddText
Range(SelectText).Value = "Shipped"
Range("L2:L" & Range("A65536").End(xlUp).Row).FillDown 'How can I dynamically change the start range here? I want to start at SelectText.


Thank you for helping
Posted
Updated 16-Dec-13 0:23am
v2
Comments
Maciej Los 16-Dec-13 10:47am    
What?
mitchiee1226 16-Dec-13 21:18pm    
Sorry if I haven't replied but I will improve the question for you.

1 solution

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:

  1. Activate Sheet1
  2. Go to Code pane (ALT+F11)
  3. Insert new module
  4. Copy and paste below code
  5. VB
    Sub TestRange()
    Range("A1") = "Test no. " & Rand()
    End Sub

  6. Run the code (F5)
  7. Go to active sheet (Sheet1) and check A1 cell value
  8. Now, go to another sheet (Sheet2) and run macro again
  9. 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:
VB
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:
VB
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900