insert row after specific date found

redspanna

Well-known Member
Joined
Jul 27, 2005
Messages
1,602
Office Version
  1. 365
Platform
  1. Windows
Hi all

Can someone please show how I can look down column A of Sheet1 for the last time a specific date is shown - this date found from cell A1 of Sheet2
When this date is found insert a row after

so for example A1 Sheet2 = 06SEP

Sheet 1 shows before code added

06SEP
06SEP
06SEP
07SEP
07SEP
07SEP

after code added and run

06SEP
06SEP
06SEP

07SEP
07SEP
07SEP


thanks in advance
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Does this work for you?

Code:
Sub Test()
    Dim LookFor As Variant
    Dim r As Long
    LookFor = Worksheets("Sheet2").Range("A1").Value
    With Worksheets("Sheet1").Range("A1").CurrentRegion.Columns(1)
        For r = .Rows.Count To 1 Step -1
            With .Cells(r, 1)
                If .Value = LookFor Then
                    .Offset(1).EntireRow.Insert
                    Exit Sub
                End If
            End With
        Next r
    End With
End Sub
 
Upvote 0
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG06Sep58
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range
    [COLOR="Navy"]Set[/COLOR] Rng = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
        [COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
            .CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng: .Item(Dn.Value) = Dn.Address: [COLOR="Navy"]Next[/COLOR]
    Range(Join(.items(), ",")).Offset(1).EntireRow.Insert
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]With[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,212,148
Messages
6,106,246
Members
448,009
Latest member
Brgrant820

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top