Iam a a beginner, and I seem to be having a lot of trouble with ranges.I wonder if you could tell me what I am doing wrong in this example.
There is a table starting in cell A3 (headings), with 3 columns of data (length undetermined).I count the number of rows:
Sub clear2()
Dim NumRows As Integer
With Worksheets(1).Range("a3")
NumRows = Range(.Offset(1, 0), .End(xlDown)).Rows.Count
So far, so good. The correct number of rows is counted. What I want to do next is select (or later on ClearContents)
the range (c4 to cNumrows).But what follows is wrong somehow.
.Range(.Offset(1, 2), .Offset(NumRows,
2)).Select
This to me should work. From A3 you offset 1 row, 2 columns, etc. But instead of selecting c4:c45, I get c6:c47 selected.
If I change the first offset so the line reads:
.Range(.Offset(-1, 2), .Offset(NumRows, 2)).Select
I get c4:c47 selected. It's almost acting as though the reference is anchored on A5 instead of A3.
Thx
There is a table starting in cell A3 (headings), with 3 columns of data (length undetermined).I count the number of rows:
Sub clear2()
Dim NumRows As Integer
With Worksheets(1).Range("a3")
NumRows = Range(.Offset(1, 0), .End(xlDown)).Rows.Count
So far, so good. The correct number of rows is counted. What I want to do next is select (or later on ClearContents)
the range (c4 to cNumrows).But what follows is wrong somehow.
.Range(.Offset(1, 2), .Offset(NumRows,
2)).Select
This to me should work. From A3 you offset 1 row, 2 columns, etc. But instead of selecting c4:c45, I get c6:c47 selected.
If I change the first offset so the line reads:
.Range(.Offset(-1, 2), .Offset(NumRows, 2)).Select
I get c4:c47 selected. It's almost acting as though the reference is anchored on A5 instead of A3.
Thx