Search For String and add Column next to it

fredlo2008

Active Member
Joined
Jan 12, 2012
Messages
254
Hello,

I am trying to get a code that will look for a string in the first row of my workbook and insert a column next to the found cell.

Thanks a lot
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Try like this

Code:
Sub atest()
Dim Found As Range
Set Found = Rows(1).Find(what:="b", LookIn:=xlValues, lookat:=xlWhole)
If Not Found Is Nothing Then Found.EntireColumn.Insert
End Sub
 
Upvote 0
Thanks a lot. It works. But the column is inserted before the Column the text was found in. Is there a way to set it so it inserts in in front of it?
 
Upvote 0
Maybe

Code:
Sub atest()
Dim Found As Range
Set Found = Rows(1).Find(what:="b", LookIn:=xlValues, lookat:=xlWhole)
If Not Found Is Nothing Then Found.Offset(, 1).EntireColumn.Insert
End Sub
 
Upvote 0
It doesn't work for any string. I just used b for testing. You need to replace b with the search string.
 
Upvote 0

Forum statistics

Threads
1,213,517
Messages
6,114,089
Members
448,548
Latest member
harryls

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