Discussion Locked

Visual Basic Search Text and Insert Row

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hello,
I need to write a Visual Basic program that will search the Excel sheet for a number and then insert a row where that number occurs. I can write the code to search. I can also write code to insert a row at a specific location. My trouble is with inserting a row that is not known until the search function finds the correct cell.

Thanks for any suggestions!

1 reply

by litehouse

I believe this short snippet will answer your question.

Option Explicit

Public Sub FindAndInsert()
Const ValueToFind As Integer = 6
Dim rngValue As Range

Set rngValue = Me.Rows.Find(ValueToFind)
rngValue.EntireRow.Insert
End Sub

This discussion is closed to new replies.