Inserting a Row after finding a Name in colum

  • Thread starter Thread starter Dunomuch
  • Start date Start date
D

Dunomuch

I am having a problem inserting a Row into a Colum with Names, the Colum also
has empty Cells, I have to find Name and then insert a row over the Name
before continuing.
I am using the visuel Basic with excel 2007

Thanks
 
See if the following example helps.

Sub Macro1()

Dim rngColumn As Range
Dim foundCell As Range
Dim findWhat As String

With Sheets("Sheet1")
Set rngColumn = .Columns("C")
End With

'InputBox to get the value to find
findWhat = InputBox("enter name to find")

'You may need to alter the parameters
'in the Find depending on your needs.
'Example xlPart only has to have the
'required value somewhere in the cell
'whereas xlWhole, the entire cell must
'match the required value exactly.

Set foundCell = rngColumn.Find(What:=findWhat, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

If Not foundCell Is Nothing Then
foundCell.EntireRow.Insert
End If

End Sub
 
OssieMac said:
See if the following example helps.

Sub Macro1()

Dim rngColumn As Range
Dim foundCell As Range
Dim findWhat As String

With Sheets("Sheet1")
Set rngColumn = .Columns("C")
End With

'InputBox to get the value to find
findWhat = InputBox("enter name to find")

'You may need to alter the parameters
'in the Find depending on your needs.
'Example xlPart only has to have the
'required value somewhere in the cell
'whereas xlWhole, the entire cell must
'match the required value exactly.

Set foundCell = rngColumn.Find(What:=findWhat, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

If Not foundCell Is Nothing Then
foundCell.EntireRow.Insert
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top