Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 422
Default Need Unique Only in MsgBox

I'm creating code that will inform me
of what rows in my range B1:F20
have been highlighted in yellow.

Extract...
Range("B1").Select
For i = 1 To NumRows
For j = 1 To NumCols
If Rng.Cells(i, j).Interior.ColorIndex = 6 Then
Tag = True
If Tag = True Then XRow = XRow & "," & CStr(i)
End If
Next j
Next i
MsgBox "Rows " & XRow & " are yellow"
End Sub

Currently my msgbox is displaying:
Rows ,3,7,9,9,9,14,18 are yellow.

It is correct - Row 9 has 3 cells
highlighted - whereas 3,7,14,& 18
have only a single cell HLed.

What can I apply to get
the msgbox to show
Rows 3,7,9,14,18 are yellow
Elimination of the leading "," would be
a bonus,

TIA,


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 903
Default Need Unique Only in MsgBox

Hi Jim,
It would help if you indented your code, you placed the
If Tag = True Then XRow = XRow & "," & CStr(i)
belongs outside the inner loop.

Thanks for including some code to start with.
I limited the selection to the usedrange, even though formatting
has nothing to do with used range, but I'm used to making
selections of columns like B:F and you would certainly NOT
want to examine every cell in such a range. Adapt to your needs.

The corrected code

Sub test2005_1210()
Dim i As Long, j As Long, rng As Range
Dim numCols As Long, numRows As Long, xRow As String, tag As Boolean
Range("B1:F20").Select
Set rng = Intersect(Selection, ActiveSheet.UsedRange)
numRows = rng.Rows.Count
numCols = rng.Columns.Count
tag = False
For i = 1 To numRows
For j = 1 To numCols
If rng.Cells(i, j).Interior.ColorIndex = 6 Then tag = True
Next j
If tag = True Then xRow = xRow & "," & CStr(i)
tag = False
Next i
If Len(xRow) = 0 Then
MsgBox "No yellow cells"
Else
MsgBox "Rows " & Mid(xRow, 2) & " contain Yellow cells"
End If
End Sub
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"JMay" wrote in message news:n7Amf.41846$_k3.40792@dukeread01...
I'm creating code that will inform me
of what rows in my range B1:F20
have been highlighted in yellow.



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
Filer for unique records and return all column data for unique rec bseeley Excel Discussion (Misc queries) 1 September 12th 09 12:17 AM
How to pick out unique components in a list with unique and common iksuinje Excel Discussion (Misc queries) 2 August 20th 08 09:57 PM
Attempting to sort unique/only count first record in each unique g MJW[_2_] Excel Discussion (Misc queries) 3 August 10th 07 02:56 PM
unique filter results in some non-unique records. Serials Librarian Excel Discussion (Misc queries) 2 May 26th 06 09:58 PM
Formulas for...1. Counting unique cells 2. Display unique contents J Excel Programming 0 April 23rd 04 09:20 PM


All times are GMT +1. The time now is 05:39 PM.

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"