• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Find text and insert column

Dear All,

Any one please help to get VBA Script to find specific text in rows and insert column before the specific text.

Find Text : Week 4 January 2013

PFA for the sample Dump
 

Attachments

  • Insert Column.xlsx
    22.8 KB · Views: 3
Hi Lakshmi -

Try this:

Sub test()
Dim l_Col As Integer
Dim n As Integer

'Change the below sheet name and row number accordingly
l_Col = Sheets("Sheet1").Cells(2, Columns.Count).End(xlToLeft).Column
For n = 1 To l_Col
If UCase(Trim(Cells(2, n).Value)) = "WEEK 4 JANUARY 2013" Then
Cells(2, n).EntireColumn.Insert
n = n + 1
End If
Next n
End Sub
 
Hi Lakshmi -

Try this:

Sub test()
Dim l_Col As Integer
Dim n As Integer

'Change the below sheet name and row number accordingly
l_Col = Sheets("Sheet1").Cells(2, Columns.Count).End(xlToLeft).Column
For n = 1 To l_Col
If UCase(Trim(Cells(2, n).Value)) = "WEEK 4 JANUARY 2013" Then
Cells(2, n).EntireColumn.Insert
n = n + 1
End If
Next n
End Sub
Dear Asheesh,

Thanks for your script. I have removed trim and Upper case in that script then it works for me.

Thanks a lot. You save my time.
 
Back
Top