VBA: Filter rows for text, set filtered rows to Bold font

JeffHaas

New Member
Joined
Nov 29, 2016
Messages
18
I have searched quite a bit and can't put the answer to this one together.

I have a spreadsheet similar to this:

[TABLE="width: 403"]
<tbody>[TR]
[TD]Group
[/TD]
[TD]Built
[/TD]
[TD] Price
[/TD]
[TD] Fee
[/TD]
[/TR]
[TR]
[TD]Main Group 1 Abcdefg
[/TD]
[TD]426
[/TD]
[TD] $ 903.58
[/TD]
[TD] $ 2.12
[/TD]
[/TR]
[TR]
[TD]Subcategory A
[/TD]
[TD]157
[/TD]
[TD] $ 277.58
[/TD]
[TD] $ 1.77
[/TD]
[/TR]
[TR]
[TD]Subcategory B
[/TD]
[TD]125
[/TD]
[TD] $ 279.06
[/TD]
[TD] $ 2.23
[/TD]
[/TR]
[TR]
[TD]Subcategory C
[/TD]
[TD]144
[/TD]
[TD] $ 346.94
[/TD]
[TD] $ 2.41
[/TD]
[/TR]
[TR]
[TD]Main Group 2 hijklmn
[/TD]
[TD]496
[/TD]
[TD] $ 1,156.45
[/TD]
[TD] $ 2.33
[/TD]
[/TR]
[TR]
[TD]Subcategory D
[/TD]
[TD]75
[/TD]
[TD] $ 170.18
[/TD]
[TD] $ 2.27
[/TD]
[/TR]
[TR]
[TD]Subcategory E
[/TD]
[TD]152
[/TD]
[TD] $ 416.53
[/TD]
[TD] $ 2.74
[/TD]
[/TR]
[TR]
[TD]Subcategory F
[/TD]
[TD]124
[/TD]
[TD] $ 279.67
[/TD]
[TD] $ 2.26
[/TD]
[/TR]
[TR]
[TD]Subcategory H
[/TD]
[TD]145
[/TD]
[TD] $ 290.07
[/TD]
[TD] $ 2.00
[/TD]
[/TR]
[TR]
[TD]Grand Total
[/TD]
[TD]922
[/TD]
[TD] $ 2,060.03
[/TD]
[TD] $ 2.23
[/TD]
[/TR]
</tbody>[/TABLE]


I would like to filter column A for anything with "Main Group" in the name. The names can be much longer and have additional terms in them.

Then I would like to bold all rows which are filtered, so all rows with "Main Group" are bolded.

Then turn off the filter.

Thanks!
 
Show me the code Fluff provide to answer your question. I do not see any code here from Fluff.
 
Upvote 0

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
It's in post#7 that you quoted in post#8
I do not see how changing a variant to a string and removing the row with the search value is going to make the script work using a Sub routine.
Show me the sub routine.
 
Last edited:
Upvote 0
I do not understand what:
Call
Filter_Me_Now ("Peter")

Does.

Are you saying now the search value is peter?

And so then next time you have to modify this sub routine to say call Filter Me Now Jack


I'm just trying to learn here.
 
Upvote 0
Whilst I don't know how the OP will be doing it, you can have a number of different subs all calling the code in post#7, each passing a different value of "s".
For instance various different buttons, on a sheet, one called Peter, one called Paul & another called Mary.
The code for Peter might be
Code:
Sub Peter()
   Call Filter_Me_Now("Peter")
End Sub
Whilst the code for Paul might be
Code:
Sub Peter()
   Call Filter_Me_Now("Paul")
End Sub
etc
That way if the main block of code needs to be modified in the future, rather than having to change the code for Peter & Paul & Mary. There's just one sub that needs changing.
 
Upvote 0
Well thanks Fluff.
But i still do not understand

I would understand more if I actually saw the script in these New Sub routines.

Like what might change

If it's only the search value why not just have a Inputbox ask what is the search value.
 
Upvote 0
The easiest way to explain is with a demo https://1drv.ms/x/s!AtYrlcV2NWPFgRnxspc_r0v50JFZ
The complete code is
Code:
Sub All()
   Call Filter_Me_Now("<>")
End Sub

Sub Dorset()
   Call Filter_Me_Now("Dorset")
End Sub

Sub Somerset()
   Call Filter_Me_Now("Somerset")
End Sub

Sub Wilts()
   Call Filter_Me_Now("Wiltshire")
End Sub

Sub Filter_Me_Now(s As String)
   With ActiveSheet
      If .AutoFilterMode Then .AutoFilterMode = False
      .Range("A4:P4").AutoFilter 8, s
   End With
End Sub
Rather than having an input box box asking for criteria, each button passes the relevant criteria to the "main" code.
 
Upvote 0
The way I'm using this is that I'm pulling data from a service that our company uses, and then running VBA macros to format the data into reports. There are several accounts, and for each account, we generate a report in Powerpoint composed of multiple pages. So I pull one set of data for one page of the Powerpoint, run a macro, and then paste the results into the Powerpoint. Repeat for each page of the Powerpoint.

I used to have to do this manually, and a report for one client could easily take a couple of hours! And my arm was killing me when I was done.

Also, each spreadsheet in the report needs to be formatted in its own way, for best readability. I put together a macro for each sheet, customized for the data a client is interested in. So being able to bold an entire line with a single command, and not having to customize the subroutine each time we update the report or add a client, is a big help.

FYI, I have to call it like this:

Call Filter_Me_Now("*Main Category*")

The term to be filtered for needs to both be in quotes, and have the wild cards (the asterisks) used. If you leave out the wild cards, then the subroutine comes back with the message box "No Values Found". This is because the lines I'm searching for are longer than just the first term, they can be 30 or 40 characters, but they start with unique terms.

I really appreciate the help I get on this board, over time I am collecting a whole bunch of these useful little subroutines. As I need to set up a new report, I can stick them together (kind of like using Legos) and build a new macro quickly.
 
Last edited:
Upvote 0
How to use this above code to sort "begins with"
and after sorting, can the output be copied to anywhere else in a different sheet?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top