Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Writing neat code

Can anyone tell me if there is a more elegant way of writing the code
below, please?

Some explanation:
rng1 is a large list of telephone numbers people have dialled.

rng3, rng4, etc. are different ranges of telephone numbers belonging
to certain departments.

The object of the exercise is to see whether any of the departmental
phones match any on the list in rng1.

If they do, then turn the interior of the cell a particular colour
depending on the department called.

I must say that it all works well as it stands. It's just that I felt
that there must be a neater way of writing the code.

Thanks

Roderick

For Each cell In rng1
res = Application.Match(cell, rng3, 0)
If Not IsError(res) Then
cell.Interior.ColorIndex = 8
End If
Next

For Each cell In rng1
res = Application.Match(cell, rng4, 0)
If Not IsError(res) Then
cell.Interior.ColorIndex = 10
End If
Next

For Each cell In rng1
res = Application.Match(cell, rng5, 0)
If Not IsError(res) Then
cell.Interior.ColorIndex = 12
End If
Next

For Each cell In rng1
res = Application.Match(cell, rng6, 0)
If Not IsError(res) Then
cell.Interior.ColorIndex = 14
End If
Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Writing neat code


For Each cell In rng1

res = Application.Match(cell, rng3, 0)
If Not IsError(res) Then cell.Interior.ColorIndex = 8

res = Application.Match(cell, rng4, 0)
If Not IsError(res) Then cell.Interior.ColorIndex = 10

res = Application.Match(cell, rng5, 0)
If Not IsError(res) Then cell.Interior.ColorIndex = 12

res = Application.Match(cell, rng6, 0)
If Not IsError(res) Then cell.Interior.ColorIndex = 14

Next

This will execute faster, also.
--
- K Dales


"Roderick O'Regan" wrote:

Can anyone tell me if there is a more elegant way of writing the code
below, please?

Some explanation:
rng1 is a large list of telephone numbers people have dialled.

rng3, rng4, etc. are different ranges of telephone numbers belonging
to certain departments.

The object of the exercise is to see whether any of the departmental
phones match any on the list in rng1.

If they do, then turn the interior of the cell a particular colour
depending on the department called.

I must say that it all works well as it stands. It's just that I felt
that there must be a neater way of writing the code.

Thanks

Roderick

For Each cell In rng1
res = Application.Match(cell, rng3, 0)
If Not IsError(res) Then
cell.Interior.ColorIndex = 8
End If
Next

For Each cell In rng1
res = Application.Match(cell, rng4, 0)
If Not IsError(res) Then
cell.Interior.ColorIndex = 10
End If
Next

For Each cell In rng1
res = Application.Match(cell, rng5, 0)
If Not IsError(res) Then
cell.Interior.ColorIndex = 12
End If
Next

For Each cell In rng1
res = Application.Match(cell, rng6, 0)
If Not IsError(res) Then
cell.Interior.ColorIndex = 14
End If
Next

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Writing neat code

Thanks a lot.

It works a treat! And looks neater too.

Code like what it should be proper writted!

Roderick


On Fri, 30 Dec 2005 10:47:02 -0800, "K Dales"
wrote:


For Each cell In rng1

res = Application.Match(cell, rng3, 0)
If Not IsError(res) Then cell.Interior.ColorIndex = 8

res = Application.Match(cell, rng4, 0)
If Not IsError(res) Then cell.Interior.ColorIndex = 10

res = Application.Match(cell, rng5, 0)
If Not IsError(res) Then cell.Interior.ColorIndex = 12

res = Application.Match(cell, rng6, 0)
If Not IsError(res) Then cell.Interior.ColorIndex = 14

Next

This will execute faster, also.

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
Neat Trick Frank Pytel Excel Discussion (Misc queries) 4 April 21st 08 09:20 PM
Need help writing Code LeAnne Excel Discussion (Misc queries) 1 February 15th 08 03:27 PM
Sharing a neat trick MartinW Excel Discussion (Misc queries) 6 July 9th 07 12:52 AM
Need some help writing code. Erik[_6_] Excel Programming 5 February 29th 04 06:51 PM
Keeping macros neat verizon Excel Programming 6 July 16th 03 02:30 AM


All times are GMT +1. The time now is 02:51 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"