[VBA] Highlight all occurances of specific text AND insert a blank row beneath

quercus

New Member
Joined
Feb 23, 2009
Messages
19
Hello all,

I have a worksheet that has various text names in Column G. I would like to highlight all cells in column G that contain the text "T2", and then insert a blank row beneath.

Many thanks
quercus
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Well, the first part you can do with Conditional Formatting.

For the second, does this do what you need:

<font face=Calibri><SPAN style="color:#00007F">Sub</SPAN> foo()<br>    <SPAN style="color:#00007F">Dim</SPAN> i <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>        <br>            <SPAN style="color:#00007F">For</SPAN> i = Cells(Rows.Count, "G").End(xlUp).Row <SPAN style="color:#00007F">To</SPAN> 1 <SPAN style="color:#00007F">Step</SPAN> -1<br>                <SPAN style="color:#00007F">If</SPAN> Cells(i, "G").Value = "T2" <SPAN style="color:#00007F">Then</SPAN> Cells(i, "G").Offset(1).EntireRow.Insert xlShiftDown<br>            <SPAN style="color:#00007F">Next</SPAN> i<br>            <br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

HTH,
 
Upvote 0
Hey Smitty,

many thanks for the swift response! ;)

Yep already got my conditional formatting highlighting the cells, but I have many spreadsheets so just wondered whether this could be inbuilt into the macro in the first instance. Not an issue if not, I can use the conditional formatting prior to the running the VBA, it will just add an extra step making the process less efficient.

The code you provided doesn't appear to work - is it looking strictly for the text "T2" - I need it to identify cells that contain "t2" within the text, e.g. MX241T2? :rolleyes:

Quercus
 
Upvote 0

Forum statistics

Threads
1,224,516
Messages
6,179,231
Members
452,898
Latest member
Capolavoro009

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