Insert column after

Fazila

Board Regular
Joined
Nov 19, 2014
Messages
163
How can I alter this code so it inserts a column after columns containing Teacher Judgement not before?

Code:
Sub inscols2()

Dim A As Range
Dim s As String


Set A = Rows(2).Find(what:="Teacher Judgement", after:=Cells(2, 1), LookIn:=xlValues, lookat:=xlPart, _
                     SearchDirection:=xlPrevious, MatchCase:=False, SearchFormat:=False)


If Not A Is Nothing Then
    s = A.Address
    Do
        A.Resize(, 1).EntireColumn.Insert
         s = Range(s).Offset(, 1).Address
        Set A = Rows(2).FindNext(A)
    Loop Until A.Address = s
End If


End Sub

Thanks
 
Last edited:

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Thanks Fluff it is now inserting columns after, however, the loop doesn't seem to end it keeps adding columns. I only need one column to be entered after each column that contains "Teacher Judgement".

Thanks
 
Upvote 0
How about
Code:
Sub inscols2()
   Dim A As Range
   Dim s As Long, i As Long

   s = Application.CountIf(Rows(2), "Teacher Judgement")
   Set A = Range("A2")
   For i = 1 To s
      Set A = Rows(2).Find(what:="Teacher Judgement", after:=A, lookIn:=xlValues, lookat:=xlPart, _
                     SearchDirection:=xlPrevious, MatchCase:=False, SearchFormat:=False)
      A.Offset(, 1).EntireColumn.Insert
   Next i
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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