Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 336
Default Select last column

Hi,

I have some code that works perfectly. It checks the value of each row and
colours the entire row with the appropraite colour.

For lRow = 2 To 21
If Cells(lRow, 3).Value = "Yes" Then
Rows(lRow).EntireRow.Interior.ColorIndex = 50

Next lRow


What i need is for it so only colour the row until the last column. Further
to this not all rows will have data in all fields, I think i know how to
select the last column with data in it but I need t select the last column
with data in it from any row.

I hope that makes sense.

Any help is greatly appreciated.

Martin

Next lRow
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Select last column

For lRow = 2 To 21
If Cells(lRow, 3).Value = "Yes" Then
Range(Cells(lRow, 3), Cells(lRow, Columns.Count).End(xlToLeft)).Interior.ColorIndex = 50
end if
Next lRow

HTH,
Bernie
MS Excel MVP


"Martin" wrote in message
...
Hi,

I have some code that works perfectly. It checks the value of each row and
colours the entire row with the appropraite colour.

For lRow = 2 To 21
If Cells(lRow, 3).Value = "Yes" Then
Rows(lRow).EntireRow.Interior.ColorIndex = 50

Next lRow


What i need is for it so only colour the row until the last column. Further
to this not all rows will have data in all fields, I think i know how to
select the last column with data in it but I need t select the last column
with data in it from any row.

I hope that makes sense.

Any help is greatly appreciated.

Martin

Next lRow



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Select last column

Hi Martin,

It was completly clear to me.

Sub ColorRowOnYes()
Dim lRow As Long
Dim lCol As Long

For lRow = 2 To 21
If Cells(lRow, 3).Value = "Yes" Then
If IsEmpty(Cells(lRow, 256)) Then
lCol = Cells(lRow, 256).End(xlToLeft).Column
Else
lCol = 256
End If
Range(Cells(lRow, 1), Cells(lRow, lCol)).Interior.ColorIndex = 50
End If
Next
End Sub

HTH,

Wouter
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 336
Default Select last column

Thank you both.

For anyone else reading, Bernies code fills the one cell, RadarEye files all
cells in that row.

Martin

"RadarEye" wrote:

Hi Martin,

It was completly clear to me.

Sub ColorRowOnYes()
Dim lRow As Long
Dim lCol As Long

For lRow = 2 To 21
If Cells(lRow, 3).Value = "Yes" Then
If IsEmpty(Cells(lRow, 256)) Then
lCol = Cells(lRow, 256).End(xlToLeft).Column
Else
lCol = 256
End If
Range(Cells(lRow, 1), Cells(lRow, lCol)).Interior.ColorIndex = 50
End If
Next
End Sub

HTH,

Wouter

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
VBA: Column Select then Data Select then return to cell A1 James C[_2_] Excel Discussion (Misc queries) 3 February 1st 10 11:35 AM
select a column, then add rows of each column darcy Excel Discussion (Misc queries) 3 August 27th 09 12:13 AM
how to select a single column when this column cross a merged cell cnEagle Excel Programming 1 November 13th 07 04:49 AM
Shortcut to select column with data in previous column TJAC Excel Discussion (Misc queries) 1 July 10th 07 06:12 PM
select detail in column B if column A = date Dan B Excel Worksheet Functions 0 September 18th 06 04:46 PM


All times are GMT +1. The time now is 07:33 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"