Issue with With statement

R

robs3131

Similar to another post I had put up today, I am now trying to "With" to
qualify my statements. However, the code below gives me the "Run Time error
'1004': Application-defined or object defined error" error...any idea why?

With Sheets("Open Transactions")
.Range("D1").End(x1Down).Offset(1, 0).value = A.value
End With
 
D

David Messenger

Copied your code into my own version and it doesn't appear to like having D1
or D2 empty. If these are empty using xldown sends it to Row 65536 (the
bottom) and then trying to move down 1 row (by the offset) takes it out of
the scope of the sheet.

If these Cells are populated do not get the error message.
 
D

David Messenger

There is probably a more sophisticated way but using your same code logic

With Sheets("Open Transactions")
.Range("D65536").End(xlUp).Offset(1, 0).Value = A.Value
End With

This resolves your problem with having D1 or D2 blank. Note that this will
not work if anywere midway down Column D is populated.
 
R

robs3131

Thanks David! I see now what the issue was. I think I'm just going to use
an If statement saying that if D1 / D2 are blank, then select the cell below.
If they are not blank, then I'll use the logic I originally wrote.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top