Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Compare Ranges by Address

Hi Group,

Received below code from Tom Ogilvy. It gives me the addresses of the ranges
in Row(2) that is filled by grey color. What I´am trying to do is to compare
another
range to the ranges from the code below. If the new range is within some of
the
found ranges the "old" range should be set to "no color".
Are not clever enough to make an array of the given ranges or to "split"
them to
independent variables for further processing. Thankful for some help to move
along.

Brgds

CG Rosén

Dim rng As Range, cell As Range
Dim rngList() As Range, i As Long

For Each cell In Rows(2).Cells
If cell.Interior.ColorIndex = 15 Then
If rng Is Nothing Then
Set rng = cell
Else
Set rng = Union(rng, cell)
End If
End If
Next

If Not rng Is Nothing Then
MsgBox rng.Address
End If






  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Compare Ranges by Address

Sub Test_Range()

Dim rng As Range, cell As Range
Dim rngList() As Range, i As Long

For Each cell In Rows(2).Cells
If cell.Interior.ColorIndex = 15 Then
If rng Is Nothing Then
Set rng = cell
Else
Set rng = Union(rng, cell)
End If
End If
Next

'''If Not rng Is Nothing Then
'''MsgBox rng.Address
'''End If

Dim TestRange As Range
Dim result As Range
Set TestRange = Selection

''' or for example
''' Set TestRange = Range("a4:k27")

Set result = Intersect(TestRange, rng)

If Not result Is Nothing Then
' reset overlap
result.Interior.ColorIndex = 0
End If
End Sub

Patrick Molloy
Microsoft Excel MVP

-----Original Message-----
Hi Group,

Received below code from Tom Ogilvy. It gives me the

addresses of the ranges
in Row(2) that is filled by grey color. What I´am trying

to do is to compare
another
range to the ranges from the code below. If the new

range is within some of
the
found ranges the "old" range should be set to "no color".
Are not clever enough to make an array of the given

ranges or to "split"
them to
independent variables for further processing. Thankful

for some help to move
along.

Brgds

CG Rosén

Dim rng As Range, cell As Range
Dim rngList() As Range, i As Long

For Each cell In Rows(2).Cells
If cell.Interior.ColorIndex = 15 Then
If rng Is Nothing Then
Set rng = cell
Else
Set rng = Union(rng, cell)
End If
End If
Next

If Not rng Is Nothing Then
MsgBox rng.Address
End If






.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Compare Ranges by Address

Hi Patrick,

Thanks for your reply. Your code works in the way that the TestRange is set
to ColorIndex =0. If the orginal range
is "longer" than the TestRange, the "old" range is still greyed in the cells
that not was covered by the TestRange

I think I cant figure it out due to the fact that I don´t know how to deal
with the result of the rng.address from Tom´s
code. It comes like "$B$2:$D$2 , $F$2:$G$2 , $K$2:$M$2". How to "strip"
these addresses to an array or separate
variables?

Brgds

CG Rosén


"Patrick Molloy" wrote in message
...
Sub Test_Range()

Dim rng As Range, cell As Range
Dim rngList() As Range, i As Long

For Each cell In Rows(2).Cells
If cell.Interior.ColorIndex = 15 Then
If rng Is Nothing Then
Set rng = cell
Else
Set rng = Union(rng, cell)
End If
End If
Next

'''If Not rng Is Nothing Then
'''MsgBox rng.Address
'''End If

Dim TestRange As Range
Dim result As Range
Set TestRange = Selection

''' or for example
''' Set TestRange = Range("a4:k27")

Set result = Intersect(TestRange, rng)

If Not result Is Nothing Then
' reset overlap
result.Interior.ColorIndex = 0
End If
End Sub

Patrick Molloy
Microsoft Excel MVP

-----Original Message-----
Hi Group,

Received below code from Tom Ogilvy. It gives me the

addresses of the ranges
in Row(2) that is filled by grey color. What I´am trying

to do is to compare
another
range to the ranges from the code below. If the new

range is within some of
the
found ranges the "old" range should be set to "no color".
Are not clever enough to make an array of the given

ranges or to "split"
them to
independent variables for further processing. Thankful

for some help to move
along.

Brgds

CG Rosén

Dim rng As Range, cell As Range
Dim rngList() As Range, i As Long

For Each cell In Rows(2).Cells
If cell.Interior.ColorIndex = 15 Then
If rng Is Nothing Then
Set rng = cell
Else
Set rng = Union(rng, cell)
End If
End If
Next

If Not rng Is Nothing Then
MsgBox rng.Address
End If






.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default Compare Ranges by Address

use the SPLIT() function

--
Patrick Molloy
Microsoft Excel MVP
----------------------------------
"CG Rosén" wrote in message
...
Hi Patrick,

Thanks for your reply. Your code works in the way that the TestRange is

set
to ColorIndex =0. If the orginal range
is "longer" than the TestRange, the "old" range is still greyed in the

cells
that not was covered by the TestRange

I think I cant figure it out due to the fact that I don´t know how to deal
with the result of the rng.address from Tom´s
code. It comes like "$B$2:$D$2 , $F$2:$G$2 , $K$2:$M$2". How to "strip"
these addresses to an array or separate
variables?

Brgds

CG Rosén


"Patrick Molloy" wrote in message
...
Sub Test_Range()

Dim rng As Range, cell As Range
Dim rngList() As Range, i As Long

For Each cell In Rows(2).Cells
If cell.Interior.ColorIndex = 15 Then
If rng Is Nothing Then
Set rng = cell
Else
Set rng = Union(rng, cell)
End If
End If
Next

'''If Not rng Is Nothing Then
'''MsgBox rng.Address
'''End If

Dim TestRange As Range
Dim result As Range
Set TestRange = Selection

''' or for example
''' Set TestRange = Range("a4:k27")

Set result = Intersect(TestRange, rng)

If Not result Is Nothing Then
' reset overlap
result.Interior.ColorIndex = 0
End If
End Sub

Patrick Molloy
Microsoft Excel MVP

-----Original Message-----
Hi Group,

Received below code from Tom Ogilvy. It gives me the

addresses of the ranges
in Row(2) that is filled by grey color. What I´am trying

to do is to compare
another
range to the ranges from the code below. If the new

range is within some of
the
found ranges the "old" range should be set to "no color".
Are not clever enough to make an array of the given

ranges or to "split"
them to
independent variables for further processing. Thankful

for some help to move
along.

Brgds

CG Rosén

Dim rng As Range, cell As Range
Dim rngList() As Range, i As Long

For Each cell In Rows(2).Cells
If cell.Interior.ColorIndex = 15 Then
If rng Is Nothing Then
Set rng = cell
Else
Set rng = Union(rng, cell)
End If
End If
Next

If Not rng Is Nothing Then
MsgBox rng.Address
End If






.





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
compare two or more ranges tywlam Excel Worksheet Functions 3 April 23rd 09 10:18 AM
Compare ranges tywlam Excel Worksheet Functions 0 April 23rd 09 04:07 AM
Using IF to compare ranges [email protected] Excel Worksheet Functions 5 April 8th 09 06:47 PM
Compare last octet of IP address Ant[_4_] Excel Discussion (Misc queries) 6 February 5th 08 11:44 PM


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

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"