excel - VBA code to Insert a Column -


i want insert column right if string"p018" present in third row of sheet:

my code :

sub insrt() dim found range dim lr long dim integer = 1 while cells(4, i).value <> "" 'if cells(3, i).value = "p018" set found = cells(3, i).find(what:="p018", lookin:=xlvalues, lookat:=xlwhole) if found nothing goto label found.offset(, 1).entirecolumn.insert  label:     loop end sub 

this going in endless loop.

you want use standard loop loops backwards:

sub insert() dim ws worksheet dim lastcolumn long dim long   set ws = activesheet ws     lastcolumn = .cells(4, .columns.count).end(xltoleft).column      = lastcolumn 1 step -1         if .cells(3, i) = "p018" columns(i + 1).insert     next end end sub 

Comments