Hi
I've got some code where I insert the number 1 into cell D2 (after it has been cleared), then drag down the number 1 and fill a series of numbers, depending on the number of rows in column A.
So if there are 3 rows (excluding the title row ie row 1) in column A, then cells D2, D3 and D4 will be 1, 2 and 3, respectively.
If rows there are 2 rows (excluding the title row ie row 1) in column A, then cells D2, D3 will be 1 and 2, respectively.
However, the macro doesn't work if there is only 1 row of data in column A (excluding the title row), because it doesn't know that it should NOT drag any data.
Does anyone know how to prevent it from giving an error, if there is only one row of data in column A?
Thanks in advance.
I've got some code where I insert the number 1 into cell D2 (after it has been cleared), then drag down the number 1 and fill a series of numbers, depending on the number of rows in column A.
So if there are 3 rows (excluding the title row ie row 1) in column A, then cells D2, D3 and D4 will be 1, 2 and 3, respectively.
If rows there are 2 rows (excluding the title row ie row 1) in column A, then cells D2, D3 will be 1 and 2, respectively.
However, the macro doesn't work if there is only 1 row of data in column A (excluding the title row), because it doesn't know that it should NOT drag any data.
Does anyone know how to prevent it from giving an error, if there is only one row of data in column A?
Thanks in advance.
VBA Code:
'Make cell D2 = 1
Range("D2").Select
ActiveCell.Value = 1
'populate column D
Range("D2").AutoFill Range("D2:D" & Range("A" & Rows.Count).End(xlUp).Row), xlFillSeries