0

Im trying to find the range on a separate sheet.

Dim abc As Range
Dim size As Integer
size = Sheets("Misc").Cells(1, Sheets("Misc").Cells(1, 1).Rows.End(xlDown).Count)
abc = Sheets("Misc").Range("A1:A" & size)

Im struggling to get the 'size' to give me the count of the rows correctly. What am I doing wrong?

1 Answer 1

4

You will need to Set the range.

dim sz as LONG
with Sheets("Misc")
    sz = .Cells(rows.count, 1).End(xlUp).Row
    SET abc = .Range("A1:A" & sz)
end with

The row number should be sufficient. You don't really need a .Count for your purposes. Just find the last populated row by looking from the bottom up.

Sign up to request clarification or add additional context in comments.

3 Comments

In his original size = Sheets("Misc")..., wouldn't he need to add .Row, or since Size was set to Integer, VB will recognize he wants an integer, so return the row? I wouldn't think it would, correct?
The original formula was really only referencing a single cell, not a range of cells so size was only ever going to be one. The .Count should have been moved outside the last bracke, possibly as .Rows.Count. It was being used as the column parameter in the Range.Cells property. Suffice to say that there was a lot going on.
Thank you for the clarification @Jeeped.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.