PDA

View Full Version : Writing to the next empty cell



taporctv
06-14-2007, 01:00 PM
I looked around the forums and I found the code but it seems to not work for me

This is the code I have that runs everytime I want to write to column A.
If (Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp) = "") Then
Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).CopyFromRecordset RS
End If

A1 has the column header. When the code runs, nothing happens.

Bob Phillips
06-14-2007, 01:20 PM
seems not to work means what?

taporctv
06-14-2007, 01:28 PM
Well I have a column header in A1. Everytime I call the mentioned code I want to write to the next empty cell, which in this case would be A2. When the code runs, nothing writes to A2.

taporctv
06-14-2007, 01:30 PM
Ok I Ran it step by step and its not entering the If statement. Whats the correct code to determine next empty cell and writing to it.

mdmackillop
06-14-2007, 01:50 PM
There is no need to test for the first empty cell, as xlUp finds the last filled one.
Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1).CopyFromRecordset Rs
Look again at the logic of your original code. It is bound to fail if there is any filled cell in column A