Dear all,
I am new to visual basic and have been learning. I need to find all rows that has a text 'date' on the first column (col. A), replace the entire row with current row1 to row 5 (row1 to row 5 are like titles which I need to insert in many places). Would you please help with this? I have tried a lot of things and nothing works correctly. I have attached a sample spreadsheet. Thanks so much!
find rows and replace each with several rows
- catcat111
- Thread is marked as Resolved.
-
-
Re: find rows and replace each with several rows
Hi catcat111
As I understand your requirements, this Code in the attached appears to do as you suggested...let me know...
Code
Display MoreOption Explicit Sub UpdateRecords() Dim ws As Worksheet Dim LR As Long Dim lLoop As Long Dim rFoundCell As Range Application.ScreenUpdating = False Set ws = Sheets("Sheet1") With ws LR = .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _ SearchDirection:=xlPrevious).Row With .Range(.Cells(7, 1), .Cells(LR, 1)) Set rFoundCell = .Cells(1, 1) For lLoop = 1 To WorksheetFunction.CountIf(.Cells, "date") Set rFoundCell = .Find(What:="date", After:=rFoundCell, _ LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _ SearchDirection:=xlNext, MatchCase:=False) ws.Range("A1:H5").Copy .Cells(rFoundCell.Row - 6, "A").Insert Shift:=xlDown Next lLoop End With .AutoFilterMode = False LR = .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _ SearchDirection:=xlPrevious).Row .Range("A1:A" & LR).AutoFilter Field:=1, Criteria1:="date" .Range("A6:A" & LR).SpecialCells(xlCellTypeVisible).EntireRow.Delete .AutoFilterMode = False End With Application.CutCopyMode = False Application.ScreenUpdating = True End Sub
-
Re: find rows and replace each with several rows
Thanks so much jaslake. It works wonderfully. I really appreciate this .
-
Re: find rows and replace each with several rows
You're welcome...glad I could help.
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!