PC Review


Reply
Thread Tools Rate Thread

Conditional Formatting Challenge

 
 
Exceller
Guest
Posts: n/a
 
      12th Dec 2008
I've searched both posts here and on the internet, but have not found a
solution to my issue. I work in general ledgers all day and need to be able
to format the sheet whereby any instance of a particular account gets
highlighted, wherever it is on the worksheet. The problem with my particular
circumstance is that there can be various permutations of the Account Name,
depending on the number of spaces in front of it. The number of spaces that
are placed before the account name is highly variable and is determined by
the amount of "drill down" I do in the account hierarcy.

For the sake of simplicity, say I have accounts "Apple", "Orange" and
"Pear". Depending on how far down I drill on the Apple account (or other
accounts) it can appear as ' Apple, or ' Apple, or any variant of
"Apple" and preceding spaces. Note that there is an apostraphe, then any
number of spaces and then the account name. I've tried various formulae in
the Conditional Formatting utility in Excel and have not been able to "get
there", including Clean(Trim(xxxxxx and Find( and Search( functions. I'd
rather have this in VBA anyway.

So, in closing, If "Apple" is found anywhere on the worksheet, regardless of
how many spaces exist between the beginning apostrophe and the account name I
want it --and the next 10 cells to the right highlight yellow and have a
border box around the range.

Is this do-able?

Thanks.


 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      13th Dec 2008
I am not sure what you are looking for, but this snippet will find apple,
regardless of the spaces or capitalization or what comes before or after it.

Sub mit()
For Each c In Sheets(1).UsedRange 'Change to suit
If Not c Is Nothing Then
If UCase(c.Value) Like "*APPLE*" Then
c.Interior.ColorIndex = 3
End If
End If
Next
End Sub


"Exceller" wrote:

> I've searched both posts here and on the internet, but have not found a
> solution to my issue. I work in general ledgers all day and need to be able
> to format the sheet whereby any instance of a particular account gets
> highlighted, wherever it is on the worksheet. The problem with my particular
> circumstance is that there can be various permutations of the Account Name,
> depending on the number of spaces in front of it. The number of spaces that
> are placed before the account name is highly variable and is determined by
> the amount of "drill down" I do in the account hierarcy.
>
> For the sake of simplicity, say I have accounts "Apple", "Orange" and
> "Pear". Depending on how far down I drill on the Apple account (or other
> accounts) it can appear as ' Apple, or ' Apple, or any variant of
> "Apple" and preceding spaces. Note that there is an apostraphe, then any
> number of spaces and then the account name. I've tried various formulae in
> the Conditional Formatting utility in Excel and have not been able to "get
> there", including Clean(Trim(xxxxxx and Find( and Search( functions. I'd
> rather have this in VBA anyway.
>
> So, in closing, If "Apple" is found anywhere on the worksheet, regardless of
> how many spaces exist between the beginning apostrophe and the account name I
> want it --and the next 10 cells to the right highlight yellow and have a
> border box around the range.
>
> Is this do-able?
>
> Thanks.
>
>

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      13th Dec 2008
Two comments on your code...

First, I don't think the 'c' variable can ever be Nothing, so you should be
able to remove that test. Second, I think using an InStr test instead of the
Like comparison might be better for that particular search (case insensitive
word). Maybe this...

Sub MIT()
Dim C As Range
For Each C In Sheets(1).UsedRange
If InStr(1, C.Value, "apple", vbTextCompare) Then
C.Interior.ColorIndex = 3
End If
Next
End Sub

--
Rick (MVP - Excel)


"JLGWhiz" <(E-Mail Removed)> wrote in message
news:580BA370-F222-4B91-81B4-(E-Mail Removed)...
>I am not sure what you are looking for, but this snippet will find apple,
> regardless of the spaces or capitalization or what comes before or after
> it.
>
> Sub mit()
> For Each c In Sheets(1).UsedRange 'Change to suit
> If Not c Is Nothing Then
> If UCase(c.Value) Like "*APPLE*" Then
> c.Interior.ColorIndex = 3
> End If
> End If
> Next
> End Sub
>
>
> "Exceller" wrote:
>
>> I've searched both posts here and on the internet, but have not found a
>> solution to my issue. I work in general ledgers all day and need to be
>> able
>> to format the sheet whereby any instance of a particular account gets
>> highlighted, wherever it is on the worksheet. The problem with my
>> particular
>> circumstance is that there can be various permutations of the Account
>> Name,
>> depending on the number of spaces in front of it. The number of spaces
>> that
>> are placed before the account name is highly variable and is determined
>> by
>> the amount of "drill down" I do in the account hierarcy.
>>
>> For the sake of simplicity, say I have accounts "Apple", "Orange" and
>> "Pear". Depending on how far down I drill on the Apple account (or other
>> accounts) it can appear as ' Apple, or ' Apple, or any variant of
>> "Apple" and preceding spaces. Note that there is an apostraphe, then any
>> number of spaces and then the account name. I've tried various formulae
>> in
>> the Conditional Formatting utility in Excel and have not been able to
>> "get
>> there", including Clean(Trim(xxxxxx and Find( and Search( functions.
>> I'd
>> rather have this in VBA anyway.
>>
>> So, in closing, If "Apple" is found anywhere on the worksheet, regardless
>> of
>> how many spaces exist between the beginning apostrophe and the account
>> name I
>> want it --and the next 10 cells to the right highlight yellow and have a
>> border box around the range.
>>
>> Is this do-able?
>>
>> Thanks.
>>
>>


 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      13th Dec 2008
Hi Rick, I put the Nothing criteria in out of habit to avoid messages in
case it does not find anything. But you are right, it is superflous in this
case. The whole point was to illustrate that 'apple" can be found no matter
how many spaces it has or what other data may be in the cell. I don't
believe either of our snippets will answer the question of conditional
formatting to do the same job, however.

"Rick Rothstein" wrote:

> Two comments on your code...
>
> First, I don't think the 'c' variable can ever be Nothing, so you should be
> able to remove that test. Second, I think using an InStr test instead of the
> Like comparison might be better for that particular search (case insensitive
> word). Maybe this...
>
> Sub MIT()
> Dim C As Range
> For Each C In Sheets(1).UsedRange
> If InStr(1, C.Value, "apple", vbTextCompare) Then
> C.Interior.ColorIndex = 3
> End If
> Next
> End Sub
>
> --
> Rick (MVP - Excel)
>
>
> "JLGWhiz" <(E-Mail Removed)> wrote in message
> news:580BA370-F222-4B91-81B4-(E-Mail Removed)...
> >I am not sure what you are looking for, but this snippet will find apple,
> > regardless of the spaces or capitalization or what comes before or after
> > it.
> >
> > Sub mit()
> > For Each c In Sheets(1).UsedRange 'Change to suit
> > If Not c Is Nothing Then
> > If UCase(c.Value) Like "*APPLE*" Then
> > c.Interior.ColorIndex = 3
> > End If
> > End If
> > Next
> > End Sub
> >
> >
> > "Exceller" wrote:
> >
> >> I've searched both posts here and on the internet, but have not found a
> >> solution to my issue. I work in general ledgers all day and need to be
> >> able
> >> to format the sheet whereby any instance of a particular account gets
> >> highlighted, wherever it is on the worksheet. The problem with my
> >> particular
> >> circumstance is that there can be various permutations of the Account
> >> Name,
> >> depending on the number of spaces in front of it. The number of spaces
> >> that
> >> are placed before the account name is highly variable and is determined
> >> by
> >> the amount of "drill down" I do in the account hierarcy.
> >>
> >> For the sake of simplicity, say I have accounts "Apple", "Orange" and
> >> "Pear". Depending on how far down I drill on the Apple account (or other
> >> accounts) it can appear as ' Apple, or ' Apple, or any variant of
> >> "Apple" and preceding spaces. Note that there is an apostraphe, then any
> >> number of spaces and then the account name. I've tried various formulae
> >> in
> >> the Conditional Formatting utility in Excel and have not been able to
> >> "get
> >> there", including Clean(Trim(xxxxxx and Find( and Search( functions.
> >> I'd
> >> rather have this in VBA anyway.
> >>
> >> So, in closing, If "Apple" is found anywhere on the worksheet, regardless
> >> of
> >> how many spaces exist between the beginning apostrophe and the account
> >> name I
> >> want it --and the next 10 cells to the right highlight yellow and have a
> >> border box around the range.
> >>
> >> Is this do-able?
> >>
> >> Thanks.
> >>
> >>

>
>

 
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
Excel 2003 Conditional formatting challenge question John C. Microsoft Excel Misc 11 9th Nov 2009 05:11 PM
Conditional Page Break Challenge gbruintjes Microsoft Access 1 9th Mar 2009 11:46 PM
Challenge with conditional find Vic Microsoft Excel Programming 3 13th May 2007 02:40 AM
conditional formatting challenge =?Utf-8?B?YnJlbmRhbg==?= Microsoft Excel Misc 2 18th Oct 2005 08:28 AM
Conditional Formulas In Excel a Challenge =?Utf-8?B?Um9jZW1waXJl?= Microsoft Excel Misc 1 7th Nov 2004 04:32 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:35 AM.