Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default Worksheet_change question

Hi,

I am using the following code in order to color a cell in one worksheet if
the same value was typed in another worksheet.
it works fine when I am entering one value at the time and I am wondering if
it is possible to do the same if i will copy and paste several values at the
time. also it will be grate if i will be able to color not only the matching
cell but the range between A:T in the relevant row.

Thanks to Ron De Bruin for the code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ws As Worksheet
Set ws = Worksheets("Pouch log")
Dim FirstAddress As String
Dim MySearch As Variant
Dim myColor As Variant
Dim lnLastRow As Long
Dim Rng As Range
Dim I As Long
lnLastRow = Cells(Rows.Count, "B").End(xlUp).Row
If Target.Address = Range("B" & lnLastRow).Address Then
MySearch = Array(Range("B" & lnLastRow))
myColor = Array("3")
lnLastRow = ws.Cells(Rows.Count, "B").End(xlUp).Row
With ws.Range("A1:Z" & lnLastRow)
For I = LBound(MySearch) To UBound(MySearch)
Set Rng = .Find(What:=MySearch(I), After:=.Cells(.Cells.Count), _
LookIn:=xlFormula, LookAt:=xlWhole, _
SearchOrder:=xlByColumns,
SearchDirection:=xlNext, _
MatchCase:=False)

If Not Rng Is Nothing Then
FirstAddress = Rng.Address
Do
Rng.Interior.ColorIndex = myColor(I)
Set Rng = .FindNext(Rng)
Loop While Not Rng Is Nothing And Rng.Address <
FirstAddress
End If
Next I
End With
End If
End Sub

Thanks in advance for your help

Eli

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Worksheet_change question


You can change this line
Code:
--------------------
Rng.Interior.ColorIndex = myColor(I)
--------------------
for this one

Code:
--------------------
Range("A" & Rng.Row & ":T" & Rng.Row).Interior.ColorIndex = myColor(I)
--------------------



אלי;323390 Wrote:
Hi,

I am using the following code in order to color a cell in one worksheet
if
the same value was typed in another worksheet.
it works fine when I am entering one value at the time and I am
wondering if
it is possible to do the same if i will copy and paste several values
at the
time. also it will be grate if i will be able to color not only the
matching
cell but the range between A:T in the relevant row.

Thanks to Ron De Bruin for the code:

Code:
--------------------

Private Sub Worksheet_Change(ByVal Target As Range)
Dim ws As Worksheet
Set ws = Worksheets("Pouch log")
Dim FirstAddress As String
Dim MySearch As Variant
Dim myColor As Variant
Dim lnLastRow As Long
Dim Rng As Range
Dim I As Long
lnLastRow = Cells(Rows.Count, "B").End(xlUp).Row
If Target.Address = Range("B" & lnLastRow).Address Then
MySearch = Array(Range("B" & lnLastRow))
myColor = Array("3")
lnLastRow = ws.Cells(Rows.Count, "B").End(xlUp).Row
With ws.Range("A1:Z" & lnLastRow)
For I = LBound(MySearch) To UBound(MySearch)
Set Rng = .Find(What:=MySearch(I), After:=.Cells(.Cells.Count), _
LookIn:=xlFormula, LookAt:=xlWhole, _
SearchOrder:=xlByColumns,
SearchDirection:=xlNext, _
MatchCase:=False)

If Not Rng Is Nothing Then
FirstAddress = Rng.Address
Do
Rng.Interior.ColorIndex = myColor(I)
Set Rng = .FindNext(Rng)
Loop While Not Rng Is Nothing And Rng.Address <
FirstAddress
End If
Next I
End With
End If
End Sub

--------------------

Thanks in advance for your help

Eli



--
Simon Lloyd

Regards,
Simon Lloyd
'The Code Cage' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?userid=1
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=90356

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
Newbie Worksheet_Change question pkern Excel Programming 0 February 9th 09 03:27 PM
worksheet_change question HRman Excel Programming 2 March 30th 06 05:35 PM
Worksheet_Change procedure question Grant Excel Programming 0 October 1st 04 01:17 AM
Worksheet_Change procedure question Grant Excel Programming 0 September 28th 04 08:41 PM
Noob question - Worksheet_Change Rich Wallace Excel Programming 3 May 14th 04 07:53 PM


All times are GMT +1. The time now is 01:25 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright 2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"