PC Review


Reply
Thread Tools Rate Thread

Color cells that match on two sheet

 
 
John
Guest
Posts: n/a
 
      27th Dec 2009
Hi Everyone

Using XL2003
I'm new to programming and this is my first try beside a couple of Userform.
I've got a Vacation Planner on one sheet for 17 People
Second sheet is a global view showing workdays for the year for all 17 people.
Each cell is numbered to match with Julian date in Calctable sheet
Third sheet is my Calculation table. Taking Start Date End date and listing
them,
Then converting those dates in to Julian dates without the year.
I would like to colour the cells on the sheet "Globalview" that match the
holiday
This is a sample of my code "Its not working " and just can't get it. Probably
way off.
-------------------------
Private Sub Worksheet_Change(ByVal Target As Range)

Dim ws As Worksheet
Dim GV As Range
Dim CT As Range


On Error GoTo ws_exit:

With Worksheets("GlobalView")
GV = Range("c5:bc9")
End With

With Worksheets("CalcTable")
CT = Range("Julian") 'Range E3:E133
End With

For Each cell In Worksheets("Global View").Range("GV")
GV = Worksheets("CalcTable").Range("CT")

cell.Interior.ColorIndex = 10

Next cell
End Sub

I tested everything with Conditional Formatting and it works "BUT" only 3
Condition and I need 17
The link below is a JPEG showing a snippet of the 3 sheets to give a better idea
I hope
http://www.mediafire.com/?zczmqzngm40
Thanking you in advance
John

 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      27th Dec 2009
For Each cell In Worksheets("Global View").Range("GV")
GV = Worksheets("CalcTable").Range("CT")

This looks like the culprit. Try replacing it with this:

For Each cell In GV.Cells
cell = Worksheets("CalcTable").Range("CT")





"John" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Everyone
>
> Using XL2003
> I'm new to programming and this is my first try beside a couple of
> Userform.
> I've got a Vacation Planner on one sheet for 17 People
> Second sheet is a global view showing workdays for the year for all 17
> people. Each cell is numbered to match with Julian date in Calctable sheet
> Third sheet is my Calculation table. Taking Start Date End date and
> listing them,
> Then converting those dates in to Julian dates without the year.
> I would like to colour the cells on the sheet "Globalview" that match the
> holiday
> This is a sample of my code "Its not working " and just can't get it.
> Probably way off.
> -------------------------
> Private Sub Worksheet_Change(ByVal Target As Range)
>
> Dim ws As Worksheet
> Dim GV As Range
> Dim CT As Range
>
>
> On Error GoTo ws_exit:
>
> With Worksheets("GlobalView")
> GV = Range("c5:bc9")
> End With
>
> With Worksheets("CalcTable")
> CT = Range("Julian") 'Range E3:E133
> End With
>
> For Each cell In Worksheets("Global View").Range("GV")
> GV = Worksheets("CalcTable").Range("CT")
>
> cell.Interior.ColorIndex = 10
>
> Next cell
> End Sub
>
> I tested everything with Conditional Formatting and it works "BUT" only 3
> Condition and I need 17
> The link below is a JPEG showing a snippet of the 3 sheets to give a
> better idea I hope
> http://www.mediafire.com/?zczmqzngm40
> Thanking you in advance
> John
>



 
Reply With Quote
 
OssieMac
Guest
Posts: n/a
 
      27th Dec 2009
Hi John,

I can't really answer your question because I don't understand exactly what
you are trying to do. However, I will point out some errors in the coding.

Firstly it is good practice to dimension your variables as follows.

Dim GV As Range
Dim CT As Range
Dim cell As Range


In the following code when using With you need to include the stop (.) in
front of Range.
Also when assigning a range to a variable you use Set.
With Worksheets("GlobalView")
Set GV = .Range("c5:bc9")
End With

As per previous comments for the following code.
With Worksheets("CalcTable")
Set CT = .Range("Julian") 'Range E3:E133
End With

When you have assigned a range in a worksheet to a variable you only use the
variable in lieu of the worksheet and range as follows.
For Each cell In GV

I have no idea what the following line is supposed to do but in any case it
is incorrect.
GV = Worksheets("CalcTable").Range("CT")

However, when assigning a range to a variable you do not use CT in the
format you have used it. (CT is not a named range; it is a VBA variable.)
Because you have already assigned a range to CT. If you then want to assign
that range to another variabe it would be as follows.
Set GV = CT

The following line would assign the interior color of every cell in the
range GV.
cell.Interior.ColorIndex = 10

Next cell

In addition to the above, you need to understand that a range assigned to a
variable in VBA is not the same as a named range on a worksheet. A named
range on a worksheet is saved with the worksheet and is available next time
the worksheet is opened. The VBA variable to which a range is assigned looses
its contents. It appears that you have a named range "Julian" while GV and CT
are VBA variables.

To help you to actually code what you are trying to achieve, it will be
necessary for you to provide a detailed description of your requirements.

--
Regards,

OssieMac


"John" wrote:

> Hi Everyone
>
> Using XL2003
> I'm new to programming and this is my first try beside a couple of Userform.
> I've got a Vacation Planner on one sheet for 17 People
> Second sheet is a global view showing workdays for the year for all 17 people.
> Each cell is numbered to match with Julian date in Calctable sheet
> Third sheet is my Calculation table. Taking Start Date End date and listing
> them,
> Then converting those dates in to Julian dates without the year.
> I would like to colour the cells on the sheet "Globalview" that match the
> holiday
> This is a sample of my code "Its not working " and just can't get it. Probably
> way off.
> -------------------------
> Private Sub Worksheet_Change(ByVal Target As Range)
>
> Dim ws As Worksheet
> Dim GV As Range
> Dim CT As Range
>
>
> On Error GoTo ws_exit:
>
> With Worksheets("GlobalView")
> GV = Range("c5:bc9")
> End With
>
> With Worksheets("CalcTable")
> CT = Range("Julian") 'Range E3:E133
> End With
>
> For Each cell In Worksheets("Global View").Range("GV")
> GV = Worksheets("CalcTable").Range("CT")
>
> cell.Interior.ColorIndex = 10
>
> Next cell
> End Sub
>
> I tested everything with Conditional Formatting and it works "BUT" only 3
> Condition and I need 17
> The link below is a JPEG showing a snippet of the 3 sheets to give a better idea
> I hope
> http://www.mediafire.com/?zczmqzngm40
> Thanking you in advance
> John
>
> .
>

 
Reply With Quote
 
John
Guest
Posts: n/a
 
      27th Dec 2009
Thank you for your help,

My Code:"Revised but not working" I'm missing something

Private Sub Worksheet_Change(ByVal Target As Range)
Dim ws As Worksheet
Dim GV As Range
Dim CT As Range

On Error GoTo ws_exit:

With Worksheets("GlobalView")
GV = .Range("c5:bc9")
End With

With Worksheets("CalcTable")
CT = .Range("Julian") 'Range E3:E133
End With

For Each cell GV.cells
cell = Worksheets("CalcTable").Range("CT")
cell.Interior.ColorIndex = 10
Next cell
End Sub
------------------------
What I'm trying to do is "Color" the cell in Worksheet ("GlobalView") that match
in worksheet ("CalcTable").
Every cell in the range ("GV") in GlobalView is numbered and when a number
appear in the range ("CT") on Worksheet ("Calctable") that match I want the cell
in GlobalView to change color.
Please let me know if you need further information
Regards
John
"OssieMac" <(E-Mail Removed)> wrote in message
news8792EA6-1FE9-4ABD-AE40-(E-Mail Removed)...
> Hi John,
>
> I can't really answer your question because I don't understand exactly what
> you are trying to do. However, I will point out some errors in the coding.
>
> Firstly it is good practice to dimension your variables as follows.
>
> Dim GV As Range
> Dim CT As Range
> Dim cell As Range
>
>
> In the following code when using With you need to include the stop (.) in
> front of Range.
> Also when assigning a range to a variable you use Set.
> With Worksheets("GlobalView")
> Set GV = .Range("c5:bc9")
> End With
>
> As per previous comments for the following code.
> With Worksheets("CalcTable")
> Set CT = .Range("Julian") 'Range E3:E133
> End With
>
> When you have assigned a range in a worksheet to a variable you only use the
> variable in lieu of the worksheet and range as follows.
> For Each cell In GV
>
> I have no idea what the following line is supposed to do but in any case it
> is incorrect.
> GV = Worksheets("CalcTable").Range("CT")
>
> However, when assigning a range to a variable you do not use CT in the
> format you have used it. (CT is not a named range; it is a VBA variable.)
> Because you have already assigned a range to CT. If you then want to assign
> that range to another variabe it would be as follows.
> Set GV = CT
>
> The following line would assign the interior color of every cell in the
> range GV.
> cell.Interior.ColorIndex = 10
>
> Next cell
>
> In addition to the above, you need to understand that a range assigned to a
> variable in VBA is not the same as a named range on a worksheet. A named
> range on a worksheet is saved with the worksheet and is available next time
> the worksheet is opened. The VBA variable to which a range is assigned looses
> its contents. It appears that you have a named range "Julian" while GV and CT
> are VBA variables.
>
> To help you to actually code what you are trying to achieve, it will be
> necessary for you to provide a detailed description of your requirements.
>
> --
> Regards,
>
> OssieMac
>
>
> "John" wrote:
>
>> Hi Everyone
>>
>> Using XL2003
>> I'm new to programming and this is my first try beside a couple of Userform.
>> I've got a Vacation Planner on one sheet for 17 People
>> Second sheet is a global view showing workdays for the year for all 17
>> people.
>> Each cell is numbered to match with Julian date in Calctable sheet
>> Third sheet is my Calculation table. Taking Start Date End date and listing
>> them,
>> Then converting those dates in to Julian dates without the year.
>> I would like to colour the cells on the sheet "Globalview" that match the
>> holiday
>> This is a sample of my code "Its not working " and just can't get it.
>> Probably
>> way off.
>> -------------------------
>> Private Sub Worksheet_Change(ByVal Target As Range)
>>
>> Dim ws As Worksheet
>> Dim GV As Range
>> Dim CT As Range
>>
>>
>> On Error GoTo ws_exit:
>>
>> With Worksheets("GlobalView")
>> GV = Range("c5:bc9")
>> End With
>>
>> With Worksheets("CalcTable")
>> CT = Range("Julian") 'Range E3:E133
>> End With
>>
>> For Each cell In Worksheets("Global View").Range("GV")
>> GV = Worksheets("CalcTable").Range("CT")
>>
>> cell.Interior.ColorIndex = 10
>>
>> Next cell
>> End Sub
>>
>> I tested everything with Conditional Formatting and it works "BUT" only 3
>> Condition and I need 17
>> The link below is a JPEG showing a snippet of the 3 sheets to give a better
>> idea
>> I hope
>> http://www.mediafire.com/?zczmqzngm40
>> Thanking you in advance
>> John
>>
>> .
>>


 
Reply With Quote
 
John
Guest
Posts: n/a
 
      27th Dec 2009
Thank you both for your help,

My Code:"Revised but not working" I'm missing something

Private Sub Worksheet_Change(ByVal Target As Range)
Dim ws As Worksheet
Dim GV As Range
Dim CT As Range

On Error GoTo ws_exit:

With Worksheets("GlobalView")
GV = .Range("c5:bc9")
End With

With Worksheets("CalcTable")
CT = .Range("Julian") 'Range E3:E133
End With

For Each cell GV.cells
cell = Worksheets("CalcTable").Range("CT")
cell.Interior.ColorIndex = 10
Next cell
End Sub
------------------------
What I'm trying to do is "Color" the cell in Worksheet ("GlobalView") that match
in worksheet ("CalcTable").
Every cell in the range ("GV") in GlobalView is numbered and when a number
appear in the range ("CT") on Worksheet ("Calctable") that match I want the cell
in GlobalView to change color.
Please let me know if you need further information
Regards
John

"John" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Everyone
>
> Using XL2003
> I'm new to programming and this is my first try beside a couple of Userform.
> I've got a Vacation Planner on one sheet for 17 People
> Second sheet is a global view showing workdays for the year for all 17 people.
> Each cell is numbered to match with Julian date in Calctable sheet
> Third sheet is my Calculation table. Taking Start Date End date and listing
> them,
> Then converting those dates in to Julian dates without the year.
> I would like to colour the cells on the sheet "Globalview" that match the
> holiday
> This is a sample of my code "Its not working " and just can't get it. Probably
> way off.
> -------------------------
> Private Sub Worksheet_Change(ByVal Target As Range)
>
> Dim ws As Worksheet
> Dim GV As Range
> Dim CT As Range
>
>
> On Error GoTo ws_exit:
>
> With Worksheets("GlobalView")
> GV = Range("c5:bc9")
> End With
>
> With Worksheets("CalcTable")
> CT = Range("Julian") 'Range E3:E133
> End With
>
> For Each cell In Worksheets("Global View").Range("GV")
> GV = Worksheets("CalcTable").Range("CT")
>
> cell.Interior.ColorIndex = 10
>
> Next cell
> End Sub
>
> I tested everything with Conditional Formatting and it works "BUT" only 3
> Condition and I need 17
> The link below is a JPEG showing a snippet of the 3 sheets to give a better
> idea I hope
> http://www.mediafire.com/?zczmqzngm40
> Thanking you in advance
> John
>


 
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
Copy a value from one sheet if two cells match =?Utf-8?B?RnV6emJ1Y2tldA==?= Microsoft Excel Misc 3 22nd Feb 2007 08:52 AM
Re: two sheet indirect match with color conditioning Don Guillett Microsoft Excel Discussion 1 20th Dec 2006 06:10 PM
Check if 2 cells match on another sheet then lookup value sarahmarsden Microsoft Excel Worksheet Functions 1 20th Oct 2006 12:19 PM
Copying a column to a new sheet so that cells match. =?Utf-8?B?TmFkZWVt?= Microsoft Excel Worksheet Functions 0 11th Oct 2005 02:03 PM
Excel: match two cells in one sheet to two cells in another and return a third cells value Spence Microsoft Excel Worksheet Functions 2 19th Jul 2005 04:19 AM


Features
 

Advertising
 

Newsgroups
 


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