gpt-3.5-turbo-0301· openai
Suzhen/CodeChat
I am working in Excel VB, the following range (Range("$A$1:$I$70")), is selecting the…
- User
I am working in Excel VB, the following range (Range("1:70")), is selecting the whole range until reaching the 70th row, how to make the number 70 a variable that indicate the last filled column
- Assistant
To find the last row in a specific column, you can use the following code:
codeDim lastRow as Long lastRow = Cells(Rows.Count, "A").End(xlUp).RowThis code will find the last non-empty row in column A. To adapt this code to your question, you can replace "A" with the column that contains the last filled row in your range.
For example, if the last filled row is in column I, you can use:
codeDim lastRow as Long lastRow = Cells(Rows.Count, "I").End(xlUp).RowThen, you can define your range using this variable:
codeDim myRange as Range Set myRange = Range("$A$1:$I$" & lastRow)