0

Here is my code

Range("C31").Select

Selection.End(xlDown).Offset(1, 0).Select

Working fine if 2 or more lines pasted in C31. But It has error if C31 has only 1 line item as xlDown will go to the bottom of the file and Offset 1,0 will totally not work.

Is there a better code for "Selection.End(xlDown).Offset(1, 0).Select"?

if found 1 line in C31 to use code is: Range("C31").Offset(1, 0).Select.. and vice versa..

Cant seem to find simple code, for simple IF code

Mike Szyndel
  • 10,461
  • 10
  • 47
  • 63
Gurenn
  • 1
  • 1
  • ... and to improve your code, study [How to avoid using Select in Excel VBA](https://stackoverflow.com/q/10714251). – VBasic2008 Apr 04 '23 at 11:06

1 Answers1

0

Not sure what you are trying to do exactly, but this would work:

ActiveSheet.Range("C31").Select
If Selection.Offset(1, 0) <> "" Then
    Range(Selection, Selection.End(xlDown)).Select
End If

Try this variation:

ActiveSheet.Range("C1").Select
If Selection.Offset(1, 0) <> "" Then
    Selection.End(xlDown).Select
End If
If Selection.Row <> 1048576 Then
    Selection.Offset(1, 0).Select
End If
Hariuss
  • 1
  • 2