PC Review


Reply
Thread Tools Rate Thread

How can I modify my code to offset the defined range and repeat theprocedure instead of duplicating my code?

 
 
najisaadat@gmail.com
Guest
Posts: n/a
 
      29th May 2009
Happy Friday Excel Community! I could really use some help with this.
I have the following code but I want it to offset and repeat the
srcRng for different ranges. I pretty much need this sub procedure to
be repeated for

ckRng("F4:Y4"), ckRng("F6:Y6"), ckRng("F8:Y8"), etc. How can I do
this? Offset the range? Add another loop? I tried a couple things but
it didn't work! Thanks a bunch for any help!

Sub colorMe()
Dim srcRng As Range, ckRng As Range, Clr As Range
Set srcRng = ActiveSheet.Range("C64:C67")
Set ckRng = ActiveSheet.Range("F4:Y4")

Ship1 = Worksheets("Sheet1").Range("C64").Value
Ship2 = Worksheets("Sheet1").Range("C65").Value
Ship3 = Worksheets("Sheet1").Range("C66").Value
Ship4 = Worksheets("Sheet1").Range("C67").Value


For Each c In ckRng
Set Clr = srcRng.Find(c.Value, LookIn:=xlValues)
If Not Clr Is Nothing Then
Select Case Clr.Value

Case Ship1
c.Offset(-1, 0).Interior.ColorIndex = 0
Case Ship2
c.Offset(-1, 0).Interior.ColorIndex = 7
Case Ship3
c.Offset(-1, 0).Interior.ColorIndex = 6
Case Ship4
c.Offset(-1, 0).Interior.ColorIndex = 8



End Select
End If
Next
End Sub
 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      29th May 2009
1. Do you want to move the ckRng exactly two rows on each iteration?

2. And for how many rows? (i.e. What is the final row to check?)

<(E-Mail Removed)> wrote in message
news:8bcf55e3-4e7c-44f3-bddd-(E-Mail Removed)...
> Happy Friday Excel Community! I could really use some help with this.
> I have the following code but I want it to offset and repeat the
> srcRng for different ranges. I pretty much need this sub procedure to
> be repeated for
>
> ckRng("F4:Y4"), ckRng("F6:Y6"), ckRng("F8:Y8"), etc. How can I do
> this? Offset the range? Add another loop? I tried a couple things but
> it didn't work! Thanks a bunch for any help!
>
> Sub colorMe()
> Dim srcRng As Range, ckRng As Range, Clr As Range
> Set srcRng = ActiveSheet.Range("C64:C67")
> Set ckRng = ActiveSheet.Range("F4:Y4")
>
> Ship1 = Worksheets("Sheet1").Range("C64").Value
> Ship2 = Worksheets("Sheet1").Range("C65").Value
> Ship3 = Worksheets("Sheet1").Range("C66").Value
> Ship4 = Worksheets("Sheet1").Range("C67").Value
>
>
> For Each c In ckRng
> Set Clr = srcRng.Find(c.Value, LookIn:=xlValues)
> If Not Clr Is Nothing Then
> Select Case Clr.Value
>
> Case Ship1
> c.Offset(-1, 0).Interior.ColorIndex = 0
> Case Ship2
> c.Offset(-1, 0).Interior.ColorIndex = 7
> Case Ship3
> c.Offset(-1, 0).Interior.ColorIndex = 6
> Case Ship4
> c.Offset(-1, 0).Interior.ColorIndex = 8
>
>
>
> End Select
> End If
> Next
> End Sub



 
Reply With Quote
 
najisaadat@gmail.com
Guest
Posts: n/a
 
      29th May 2009
Hey JLG!

Yes, exactly 2 rows on each iteration, with the last row for ckRng
being F116:Y116.

Thanks a bunch JLG, you are a true Whiz!


On May 29, 1:06*pm, "JLGWhiz" <JLGW...@cfl.rr.com> wrote:
> 1. *Do you want to move the ckRng exactly two rows on each iteration?
>
> 2. *And for how many rows? *(i.e. What is the final row to check?)
>
> <najisaa...@gmail.com> wrote in message
>
> news:8bcf55e3-4e7c-44f3-bddd-(E-Mail Removed)...
>
>
>
> > Happy Friday Excel Community! I could really use some help with this.
> > I have the following code but I want it to offset and repeat the
> > srcRng for different ranges. I pretty much need this sub procedure to
> > be repeated for

>
> > ckRng("F4:Y4"), ckRng("F6:Y6"), ckRng("F8:Y8"), etc. How can I do
> > this? Offset the range? Add another loop? I tried a couple things but
> > it didn't work! Thanks a bunch for any help!

>
> > Sub colorMe()
> > * Dim srcRng As Range, ckRng As Range, Clr As Range
> > * Set srcRng = ActiveSheet.Range("C64:C67")
> > * Set ckRng = ActiveSheet.Range("F4:Y4")

>
> > * Ship1 = Worksheets("Sheet1").Range("C64").Value
> > * Ship2 = Worksheets("Sheet1").Range("C65").Value
> > * Ship3 = Worksheets("Sheet1").Range("C66").Value
> > * Ship4 = Worksheets("Sheet1").Range("C67").Value

>
> > * For Each c In ckRng
> > * * Set Clr = srcRng.Find(c.Value, LookIn:=xlValues)
> > * * * If Not Clr Is Nothing Then
> > * * * * *Select Case Clr.Value

>
> > * * * * * Case Ship1
> > * * * * * * *c.Offset(-1, 0).Interior.ColorIndex = 0
> > * * * * * Case Ship2
> > * * * * * * *c.Offset(-1, 0).Interior.ColorIndex = 7
> > * * * * * Case Ship3
> > * * * * * * *c.Offset(-1, 0).Interior.ColorIndex = 6
> > * * * * * Case Ship4
> > * * * * * * *c.Offset(-1, 0).Interior.ColorIndex = 8

>
> > * * * * *End Select
> > * * * End If
> > * * Next
> > End Sub- Hide quoted text -

>
> - Show quoted text -


 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      29th May 2009
Try this:

Sub colorMe()
Dim srcRng As Range, ckRng As Range, Clr As Range
Set srcRng = ActiveSheet.Range("C64:C67")
Ship1 = Worksheets("Sheet1").Range("C64").Value
Ship2 = Worksheets("Sheet1").Range("C65").Value
Ship3 = Worksheets("Sheet1").Range("C66").Value
Ship4 = Worksheets("Sheet1").Range("C67").Value
For i = 4 To 116 Step 2
Set ckRng = ActiveSheet.Range("F" & i & ":Y" & i)
For Each c In ckRng
Set Clr = srcRng.Find(c.Value, LookIn:=xlValues)
If Not Clr Is Nothing Then
Select Case Clr.Value
Case Ship1
c.Offset(-1, 0).Interior.ColorIndex = 0
Case Ship2
c.Offset(-1, 0).Interior.ColorIndex = 7
Case Ship3
c.Offset(-1, 0).Interior.ColorIndex = 6
Case Ship4
c.Offset(-1, 0).Interior.ColorIndex = 8
End Select
End If
Next
Next
End Sub



<(E-Mail Removed)> wrote in message
news:ab0721b8-7731-4987-a346-(E-Mail Removed)...
Hey JLG!

Yes, exactly 2 rows on each iteration, with the last row for ckRng
being F116:Y116.

Thanks a bunch JLG, you are a true Whiz!


On May 29, 1:06 pm, "JLGWhiz" <JLGW...@cfl.rr.com> wrote:
> 1. Do you want to move the ckRng exactly two rows on each iteration?
>
> 2. And for how many rows? (i.e. What is the final row to check?)
>
> <najisaa...@gmail.com> wrote in message
>
> news:8bcf55e3-4e7c-44f3-bddd-(E-Mail Removed)...
>
>
>
> > Happy Friday Excel Community! I could really use some help with this.
> > I have the following code but I want it to offset and repeat the
> > srcRng for different ranges. I pretty much need this sub procedure to
> > be repeated for

>
> > ckRng("F4:Y4"), ckRng("F6:Y6"), ckRng("F8:Y8"), etc. How can I do
> > this? Offset the range? Add another loop? I tried a couple things but
> > it didn't work! Thanks a bunch for any help!

>
> > Sub colorMe()
> > Dim srcRng As Range, ckRng As Range, Clr As Range
> > Set srcRng = ActiveSheet.Range("C64:C67")
> > Set ckRng = ActiveSheet.Range("F4:Y4")

>
> > Ship1 = Worksheets("Sheet1").Range("C64").Value
> > Ship2 = Worksheets("Sheet1").Range("C65").Value
> > Ship3 = Worksheets("Sheet1").Range("C66").Value
> > Ship4 = Worksheets("Sheet1").Range("C67").Value

>
> > For Each c In ckRng
> > Set Clr = srcRng.Find(c.Value, LookIn:=xlValues)
> > If Not Clr Is Nothing Then
> > Select Case Clr.Value

>
> > Case Ship1
> > c.Offset(-1, 0).Interior.ColorIndex = 0
> > Case Ship2
> > c.Offset(-1, 0).Interior.ColorIndex = 7
> > Case Ship3
> > c.Offset(-1, 0).Interior.ColorIndex = 6
> > Case Ship4
> > c.Offset(-1, 0).Interior.ColorIndex = 8

>
> > End Select
> > End If
> > Next
> > End Sub- Hide quoted text -

>
> - Show quoted text -



 
Reply With Quote
 
najisaadat@gmail.com
Guest
Posts: n/a
 
      29th May 2009
Works like a charm! Thanks!

On May 29, 1:30*pm, "JLGWhiz" <JLGW...@cfl.rr.com> wrote:
> Try this:
>
> Sub colorMe()
> * *Dim srcRng As Range, ckRng As Range, Clr As Range
> * *Set srcRng = ActiveSheet.Range("C64:C67")
> * *Ship1 = Worksheets("Sheet1").Range("C64").Value
> * *Ship2 = Worksheets("Sheet1").Range("C65").Value
> * *Ship3 = Worksheets("Sheet1").Range("C66").Value
> * *Ship4 = Worksheets("Sheet1").Range("C67").Value
> * *For i = 4 To 116 Step 2
> * * *Set ckRng = ActiveSheet.Range("F" & i & ":Y" & i)
> * * *For Each c In ckRng
> * * *Set Clr = srcRng.Find(c.Value, LookIn:=xlValues)
> * * * *If Not Clr Is Nothing Then
> * * * * * Select Case Clr.Value
> * * * * * *Case Ship1
> * * * * * * * c.Offset(-1, 0).Interior.ColorIndex = 0
> * * * * * *Case Ship2
> * * * * * * * c.Offset(-1, 0).Interior.ColorIndex = 7
> * * * * * *Case Ship3
> * * * * * * * c.Offset(-1, 0).Interior.ColorIndex = 6
> * * * * * *Case Ship4
> * * * * * * * c.Offset(-1, 0).Interior.ColorIndex = 8
> * * * * * End Select
> * * * *End If
> * * *Next
> * * *Next
> End Sub
>
> <najisaa...@gmail.com> wrote in message
>
> news:ab0721b8-7731-4987-a346-(E-Mail Removed)...
> Hey JLG!
>
> Yes, exactly 2 rows on each iteration, with the last row for ckRng
> being F116:Y116.
>
> Thanks a bunch JLG, you are a true Whiz!
>
> On May 29, 1:06 pm, "JLGWhiz" <JLGW...@cfl.rr.com> wrote:
>
>
>
> > 1. Do you want to move the ckRng exactly two rows on each iteration?

>
> > 2. And for how many rows? (i.e. What is the final row to check?)

>
> > <najisaa...@gmail.com> wrote in message

>
> >news:8bcf55e3-4e7c-44f3-bddd-(E-Mail Removed)...

>
> > > Happy Friday Excel Community! I could really use some help with this.
> > > I have the following code but I want it to offset and repeat the
> > > srcRng for different ranges. I pretty much need this sub procedure to
> > > be repeated for

>
> > > ckRng("F4:Y4"), ckRng("F6:Y6"), ckRng("F8:Y8"), etc. How can I do
> > > this? Offset the range? Add another loop? I tried a couple things but
> > > it didn't work! Thanks a bunch for any help!

>
> > > Sub colorMe()
> > > Dim srcRng As Range, ckRng As Range, Clr As Range
> > > Set srcRng = ActiveSheet.Range("C64:C67")
> > > Set ckRng = ActiveSheet.Range("F4:Y4")

>
> > > Ship1 = Worksheets("Sheet1").Range("C64").Value
> > > Ship2 = Worksheets("Sheet1").Range("C65").Value
> > > Ship3 = Worksheets("Sheet1").Range("C66").Value
> > > Ship4 = Worksheets("Sheet1").Range("C67").Value

>
> > > For Each c In ckRng
> > > Set Clr = srcRng.Find(c.Value, LookIn:=xlValues)
> > > If Not Clr Is Nothing Then
> > > Select Case Clr.Value

>
> > > Case Ship1
> > > c.Offset(-1, 0).Interior.ColorIndex = 0
> > > Case Ship2
> > > c.Offset(-1, 0).Interior.ColorIndex = 7
> > > Case Ship3
> > > c.Offset(-1, 0).Interior.ColorIndex = 6
> > > Case Ship4
> > > c.Offset(-1, 0).Interior.ColorIndex = 8

>
> > > End Select
> > > End If
> > > Next
> > > End Sub- Hide quoted text -

>
> > - Show quoted text -- Hide quoted text -

>
> - Show quoted text -


 
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
Modify RDB code with find and offset John Yab Microsoft Excel Programming 6 3rd Sep 2009 02:58 AM
Dynamic Range & Offset code problem JoAnn Microsoft Excel Programming 3 30th Sep 2008 06:08 PM
Need code to replace part of a range within a formula with a defined name Jeff Microsoft Excel Programming 2 2nd May 2006 10:59 PM
Dynamic Range Offset causing problem with this code Arishy Microsoft Excel Programming 1 3rd Aug 2005 06:15 PM
How to call code in aspx webform from functions defined in code behind modules CW Microsoft ASP .NET 3 2nd May 2004 03:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:58 PM.