View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Ryan H Ryan H is offline
external usenet poster
 
Posts: 489
Default Cell not selecting

Your problem is you haven't assigned anything to rng so rng will always be
Nothing until you do assign it something. Do you have some code missing from
your post? Are you wanting to select the last cell, if not, which cell are
you wanting to select? Try the code below.

Note: I would recommend you put Option Explicit at the top of your module
which will force declaration of all variables and ensure you have not spelled
anything incorrectly.


Option Explicit

Sub RangeSelect()

Dim lngLastRow As Long
Dim rng As Range

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
If Not rng Is Nothing Then
rng.Select
End If
End If
End If

End Sub
--
Cheers,
Ryan


"Gotroots" wrote:

The last blank cell containing the value of "B9" does not rng.Select. Much
appreciate if someone could advise me as to why.

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
If rng Is Nothing Then
Else
rng.Select
End If
End If
End If

End Sub