Shift Excel Row Based on Cell Value

March 23, 2009 at 16:46:02
Specs: Windows XP
I have an excel spreadsheet with two columns
of data. The first column is all descriptors. The
second column is data that pertains to the
descriptors in the first column.
I need a simple VBS script which will read
through the document and if a cell in column A
contains the text "file name:" (exactly that with
the ":" if possible), then a row is inserted
ABOVE the row with the text "file name:", thus
shifting all other data down one row.
The reason it has to be exactly "file name:" is
because other rows contain "file name (with
full path)". Not sure if it's an issue at all.
Thanks for the help!

See More: Shift Excel Row Based on Cell Value

Report •

March 23, 2009 at 18:12:29
It's VBA, not VBS.

Assuming your data is in Column A...

Sub Insert_Row()
'Find last row
  lRow = Range("A" & Rows.Count).End(xlUp).Row
'Start at bottom and work up
  For nxtRow = lRow To 1 Step -1
'Check for string
   If Range("A" & nxtRow) = "file name:" Then
'Insert Row if required
    Range("A" & nxtRow).EntireRow.Insert
   End If
End Sub

Report •
Related Solutions

Ask Question