PC Review


Reply
Thread Tools Rate Thread

Change code to look at a range of columns not a single column

 
 
BeSmart
Guest
Posts: n/a
 
      6th Mar 2010
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 With Quote
 
 
 
 
Mike Fogleman
Guest
Posts: n/a
 
      6th Mar 2010
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" <(E-Mail Removed)> wrote in message
news:00CD887B-36CB-4F36-AAC7-(E-Mail Removed)...
> 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 With Quote
 
BeSmart
Guest
Posts: n/a
 
      7th Mar 2010
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" <(E-Mail Removed)> wrote in message
> news:00CD887B-36CB-4F36-AAC7-(E-Mail Removed)...
> > 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


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 Microsoft Excel Programming 8 11th Feb 2010 09:14 PM
Transpose 3 columns into Single column AncientLearner Microsoft Excel Programming 4 12th Feb 2008 04:42 PM
Single column into multiple columns =?Utf-8?B?SGVpZGk=?= Microsoft Excel Misc 3 1st Nov 2006 09:27 PM
Copy column range of "single word" cells with spaces to a single c =?Utf-8?B?bmFzdGVjaA==?= Microsoft Excel Misc 3 15th Feb 2006 05:04 PM
Re: Moving several columns from a single row into a single column Heffex Microsoft Access 0 19th Feb 2004 06:35 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:38 PM.