Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Selecting a Range

Hello all,
I am trying to use the following code (courtesy of Tom Ogilvy) to
colour the range from B26 to the last occupied cell without success.
You will note that I have named the last occupied cell 'Lastcell'
thinking this will help with selection and delete it at the end as I
need to use it with different sheets in the same workbook.
Where am I going wrong?


Sub GetRealLastCell()
Dim RealLastRow As Long
Dim RealLastColumn As Long
Range("A1").Select
On Error Resume Next
RealLastRow = _
Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
RealLastColumn = _
Cells.Find("*", [A1], , , xlByColumns, xlPrevious).Column
Cells(RealLastRow, RealLastColumn).Select
ActiveWorkbook.Names.Add Name:="LastCell"
Range("b26:LastCell").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
ActiveWorkbook.Names("lastcell").Delete
End Sub

TIA
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Selecting a Range

Range("b26:LastCell").Select

should be

Range(Range("b26") , Range("LastCell")).Select

--
Regards,
Tom Ogilvy

"Karen" wrote in message
om...
Hello all,
I am trying to use the following code (courtesy of Tom Ogilvy) to
colour the range from B26 to the last occupied cell without success.
You will note that I have named the last occupied cell 'Lastcell'
thinking this will help with selection and delete it at the end as I
need to use it with different sheets in the same workbook.
Where am I going wrong?


Sub GetRealLastCell()
Dim RealLastRow As Long
Dim RealLastColumn As Long
Range("A1").Select
On Error Resume Next
RealLastRow = _
Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
RealLastColumn = _
Cells.Find("*", [A1], , , xlByColumns, xlPrevious).Column
Cells(RealLastRow, RealLastColumn).Select
ActiveWorkbook.Names.Add Name:="LastCell"
Range("b26:LastCell").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
ActiveWorkbook.Names("lastcell").Delete
End Sub

TIA



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Selecting a Range

Tom
Thank you for your reply.
I tried it out but the colouring applied to only the last cell instead
of the Range.

Karen







"Tom Ogilvy" wrote in message ...
Range("b26:LastCell").Select

should be

Range(Range("b26") , Range("LastCell")).Select

--
Regards,
Tom Ogilvy

"Karen" wrote in message
om...
Hello all,
I am trying to use the following code (courtesy of Tom Ogilvy) to
colour the range from B26 to the last occupied cell without success.
You will note that I have named the last occupied cell 'Lastcell'
thinking this will help with selection and delete it at the end as I
need to use it with different sheets in the same workbook.
Where am I going wrong?


Sub GetRealLastCell()
Dim RealLastRow As Long
Dim RealLastColumn As Long
Range("A1").Select
On Error Resume Next
RealLastRow = _
Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
RealLastColumn = _
Cells.Find("*", [A1], , , xlByColumns, xlPrevious).Column
Cells(RealLastRow, RealLastColumn).Select
ActiveWorkbook.Names.Add Name:="LastCell"
Range("b26:LastCell").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
ActiveWorkbook.Names("lastcell").Delete
End Sub

TIA

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Selecting a Range

Try it this way:

Sub GetRealLastCell()
Dim RealLastRow As Long
Dim RealLastColumn As Long
Range("A1").Select
RealLastRow = _
Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
RealLastColumn = _
Cells.Find("*", [A1], , , xlByColumns, xlPrevious).Column
With Range(Range("b26"), _
Cells(RealLastRow, RealLastColumn)).Interior
.ColorIndex = 6
.Pattern = xlSolid
End With

End Sub

--
Regards,
Tom Ogilvy

"Karen" wrote in message
om...
Tom
Thank you for your reply.
I tried it out but the colouring applied to only the last cell instead
of the Range.

Karen







"Tom Ogilvy" wrote in message

...
Range("b26:LastCell").Select

should be

Range(Range("b26") , Range("LastCell")).Select

--
Regards,
Tom Ogilvy

"Karen" wrote in message
om...
Hello all,
I am trying to use the following code (courtesy of Tom Ogilvy) to
colour the range from B26 to the last occupied cell without success.
You will note that I have named the last occupied cell 'Lastcell'
thinking this will help with selection and delete it at the end as I
need to use it with different sheets in the same workbook.
Where am I going wrong?


Sub GetRealLastCell()
Dim RealLastRow As Long
Dim RealLastColumn As Long
Range("A1").Select
On Error Resume Next
RealLastRow = _
Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
RealLastColumn = _
Cells.Find("*", [A1], , , xlByColumns, xlPrevious).Column
Cells(RealLastRow, RealLastColumn).Select
ActiveWorkbook.Names.Add Name:="LastCell"
Range("b26:LastCell").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
ActiveWorkbook.Names("lastcell").Delete
End Sub

TIA



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Selecting a Range

Tom
Thank you very much.
Perfect!

Karen










"Tom Ogilvy" wrote in message ...
Try it this way:

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting range in list of range names depending on a cell informa Courreges Excel Discussion (Misc queries) 2 June 19th 06 10:59 AM
Selecting A Range Patrick Molloy Excel Programming 0 July 22nd 03 07:54 AM
Selecting A Range russell \(skmr3\) Excel Programming 1 July 22nd 03 03:25 AM
Selecting A Range John Wilson Excel Programming 0 July 22nd 03 03:05 AM
selecting a range David Excel Programming 2 July 21st 03 11:14 PM


All times are GMT +1. The time now is 02:24 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"