Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Change code to look at a range of columns not a single column

Hi All

Could someone help me - I need to change the following code to look at the
range of columns "D:"BJ" and apply the formatting - rather than just looking
at column D? I've tried a few things and they haven't worked (I get error
msgs so I'm obviously doing it wrong)...

Where "D" appears below, I need it to look & apply to a range of "D:"BJ".

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Cell As Integer
Dim Z As Integer

For Z = 17 To Cells(Rows.Count, "C").End(xlUp).Row
For Cell = 43 To Cells(Rows.Count, "A").End(xlUp).Row
If Cells(Cell, "A").Value Like "*" & Range("C" & Z).Value & "*" Then
If Cells(Cell, "D").Value "0" Then
Cells(Cell, "D").Interior.Color = Range("C" & Z).Interior.Color
End If
End If
Next Cell
Next Z
End Sub
--
Thank for your help in advance
BeSmart
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default Change code to look at a range of columns not a single column

Try this. It will loop through the cells in columns D thru BJ on whatever
row Cell is equal to.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Cell As Integer
Dim Z As Integer
Dim c As Range, RwRng As Range

For Z = 17 To Cells(Rows.Count, "C").End(xlUp).Row
For Cell = 43 To Cells(Rows.Count, "A").End(xlUp).Row
If Cells(Cell, "A").Value Like "*" & Range("C" & Z).Value & "*" Then

Set RwRng = Range(Cells(Cell, "D"), Cells(Cell, "BJ"))
For Each c in RwRng
If c.Value "0" Then
c.Interior.Color = Range("C" & Z).Interior.Color
End If
Next c

End If
Next Cell
Next Z
End Sub

Mike F
"BeSmart" wrote in message
...
Hi All

Could someone help me - I need to change the following code to look at the
range of columns "D:"BJ" and apply the formatting - rather than just
looking
at column D? I've tried a few things and they haven't worked (I get error
msgs so I'm obviously doing it wrong)...

Where "D" appears below, I need it to look & apply to a range of "D:"BJ".

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Cell As Integer
Dim Z As Integer

For Z = 17 To Cells(Rows.Count, "C").End(xlUp).Row
For Cell = 43 To Cells(Rows.Count, "A").End(xlUp).Row
If Cells(Cell, "A").Value Like "*" & Range("C" & Z).Value & "*" Then
If Cells(Cell, "D").Value "0" Then
Cells(Cell, "D").Interior.Color = Range("C" & Z).Interior.Color
End If
End If
Next Cell
Next Z
End Sub
--
Thank for your help in advance
BeSmart



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Change code to look at a range of columns not a single column

thanks Mike
That works great - although with the size of my data it's not going to be
workable for the users (constantly updating with every enter)...
So I've adapted a similar code to run as a button activated macro.
However, I'll definitely use this code in my smaller data.
--
Thank for your help
BeSmart


"Mike Fogleman" wrote:

Try this. It will loop through the cells in columns D thru BJ on whatever
row Cell is equal to.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Cell As Integer
Dim Z As Integer
Dim c As Range, RwRng As Range

For Z = 17 To Cells(Rows.Count, "C").End(xlUp).Row
For Cell = 43 To Cells(Rows.Count, "A").End(xlUp).Row
If Cells(Cell, "A").Value Like "*" & Range("C" & Z).Value & "*" Then

Set RwRng = Range(Cells(Cell, "D"), Cells(Cell, "BJ"))
For Each c in RwRng
If c.Value "0" Then
c.Interior.Color = Range("C" & Z).Interior.Color
End If
Next c

End If
Next Cell
Next Z
End Sub

Mike F
"BeSmart" wrote in message
...
Hi All

Could someone help me - I need to change the following code to look at the
range of columns "D:"BJ" and apply the formatting - rather than just
looking
at column D? I've tried a few things and they haven't worked (I get error
msgs so I'm obviously doing it wrong)...

Where "D" appears below, I need it to look & apply to a range of "D:"BJ".

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Cell As Integer
Dim Z As Integer

For Z = 17 To Cells(Rows.Count, "C").End(xlUp).Row
For Cell = 43 To Cells(Rows.Count, "A").End(xlUp).Row
If Cells(Cell, "A").Value Like "*" & Range("C" & Z).Value & "*" Then
If Cells(Cell, "D").Value "0" Then
Cells(Cell, "D").Interior.Color = Range("C" & Z).Interior.Color
End If
End If
Next Cell
Next Z
End Sub
--
Thank for your help in advance
BeSmart



.

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
select range in column, calculate on range plus 3 columns, output inrange plus 7 columns ppeer Excel Programming 13 February 11th 10 09:14 PM
Create two columns from a single column with (first and last name) KB Excel Discussion (Misc queries) 2 August 28th 08 08:35 PM
Single column into multiple columns Heidi Excel Discussion (Misc queries) 3 November 1st 06 09:27 PM
Copy column range of "single word" cells with spaces to a single c nastech Excel Discussion (Misc queries) 3 February 15th 06 05:04 PM
Change the width of a single column in a column chart Dave Charts and Charting in Excel 2 December 13th 04 07:25 PM


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