ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Code falling over (https://www.excelbanter.com/excel-programming/437563-code-falling-over.html)

Gotroots

Code falling over
 
I am getting an error when rng.Select is inserted into the following code:

If IsEmpty(Range("b9")) Then
MsgBox "No record found in B9.", vbInformation
Else
lngLastRow = Cells(Rows.Count, "B").End(xlUp).Row ' + 1

If lngLastRow <= 10 Then
Range("B10").Value = Range("B9").Value
Else
Cells(lngLastRow, "B").Value = Range("B9").Value
rng.Select
End If
End If

How should this be included without the code falling over.

Thank you if you can be of help.


Gary''s Student

Code falling over
 
Replace:
rng.Select
with:
If rng Is Nothing Then
Else
rng.Select
End If

--
Gary''s Student - gsnu200909


"Gotroots" wrote:

I am getting an error when rng.Select is inserted into the following code:

If IsEmpty(Range("b9")) Then
MsgBox "No record found in B9.", vbInformation
Else
lngLastRow = Cells(Rows.Count, "B").End(xlUp).Row ' + 1

If lngLastRow <= 10 Then
Range("B10").Value = Range("B9").Value
Else
Cells(lngLastRow, "B").Value = Range("B9").Value
rng.Select
End If
End If

How should this be included without the code falling over.

Thank you if you can be of help.


Rick Rothstein

Code falling over
 
Where did "rng" come from? The only place I see it is in the statement you
are asking about... did you ever Set an actual range to this variable
earlier in your code somewhere? If so, then you need to look there for your
problem; if not, then that **is** your problem.

--
Rick (MVP - Excel)


"Gotroots" wrote in message
...
I am getting an error when rng.Select is inserted into the following code:

If IsEmpty(Range("b9")) Then
MsgBox "No record found in B9.", vbInformation
Else
lngLastRow = Cells(Rows.Count, "B").End(xlUp).Row ' + 1

If lngLastRow <= 10 Then
Range("B10").Value = Range("B9").Value
Else
Cells(lngLastRow, "B").Value = Range("B9").Value
rng.Select
End If
End If

How should this be included without the code falling over.

Thank you if you can be of help.



Neptune Dinosaur

Code falling over
 
You don't seem to be assigning (setting) anything to the variable "rng",
which presumably is an object variable ......


--
Time is just the thing that keeps everything from happening all at once


"Gotroots" wrote:

I am getting an error when rng.Select is inserted into the following code:

If IsEmpty(Range("b9")) Then
MsgBox "No record found in B9.", vbInformation
Else
lngLastRow = Cells(Rows.Count, "B").End(xlUp).Row ' + 1

If lngLastRow <= 10 Then
Range("B10").Value = Range("B9").Value
Else
Cells(lngLastRow, "B").Value = Range("B9").Value
rng.Select
End If
End If

How should this be included without the code falling over.

Thank you if you can be of help.



All times are GMT +1. The time now is 08:16 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com