-
I am writing a Macro in Microsoft Excel.
I know that to select e.g. row 5, I would code:
rows("5:5").select.
However, if I use a variable to move about the worksheet i.e. Range("A" & targetrow).Select (where targetrow is a variable), I can't hard-code the row selection as above.
Is there syntax to use a variable in the rows().select statement, or is there anyway of selecting 'the current row'?
-
Here's a couple ways I've done it in the past:
This one selects the row in which the activecell is in...
Code:
Public Function SelCurRow()
Dim CurRow As String
CurRow = Application.ActiveCell.Row & ":" & Application.ActiveCell.Row
Rows(CurRow).Select
End Function
This one selects a row that is determined with a variable being past to it...
Code:
Public Function SelectVarRow()
Dim CurRow As String
Dim A As String
A = InputBox("Row to select:", "Row Select")
CurRow = A & ":" & A
Rows(CurRow).Select
End Function
Hope this helps.