1

What would the equivalent to this be for the horizontal/colum?

v = Sheets("Sheet2").Range("A65536").End(xlUp).Row

I am guessing this but do not know how to check

v = Sheets("Sheet2").Range("zz1").End(xlRight).column

I am basically trying to figure out the how many columns there are. I tried what I guessed but it is wrong

2

1 Answer 1

2

To get the index of the last column in the sheet, use Cells(1,Columns.Count).Column

To get the last used Column, it is very similar.

Cells(1,Columns.Count).End(xlToLeft).Column
Sign up to request clarification or add additional context in comments.

5 Comments

make sure you qualify the range object with the sheet. Sheets("Sheet2").Cells(1,Sheets("Sheet2").Columns.Count).End(xlToLeft).Column
True, if the sheet to check the columns is not the active sheet. If it is, qualifying it is not necessary.
Would this work as well for rows?
You can use what you had above for rows. Cells(Rows.Count, 1).End(xlUp).Row
Very important: this works only if all rows have the same number of columns, otherwise it simply returns the number of columns in row 1. Replace the index 1 by the index of the longest row, or by the index of a specific row you want to check

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.