Macro

shaunkaz

Board Regular
Joined
Jan 30, 2008
Messages
204
I have two worksheets, History and Current.

The current worksheet is updated with orders every day and what I do at the moment is copy the New orders from the previous day and paste them into the History worksheet

What i want for example is on the current sheet look at order date

Order date
row 50 21 June
row 51 21 June
row 52 22 June
row 53 23 June


On the History sheet
Order date
row 3750 21 June
row 3751 21 June

What I would do then is lookup to see what dates i have not got so in this case on the history i have not got 22 june or 23 june. I would copy these lines and paste into the history sheet and the next available blank line.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Try like this. Note that History is a reserved name for a sheet so I used Sheet 2 - change to suit

Rich (BB code):
Sub Hstry()
Dim LR As Long, i As Long
With Sheets("Current")
    LR = .Range("B" & Rows.Count).End(xlUp).Row
    For i = 2 To LR
        With .Range("B" & i)
            If .Value < Date Then .EntireRow.Cut Destination:=Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
        End With
    Next i
    On Error Resume Next
    .Range("B2:B" & LR).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End With
End Sub
 
Upvote 0
Try this (adjust names).
Code:
[COLOR="Blue"]Sub[/COLOR] GoToHistory()

    [COLOR="Blue"]Dim[/COLOR] i [COLOR="Blue"]As[/COLOR] [COLOR="Blue"]Integer[/COLOR]
    [COLOR="Blue"]Dim[/COLOR] shHistory [COLOR="Blue"]As[/COLOR] Worksheet, shCurrent [COLOR="Blue"]As[/COLOR] Worksheet
    [COLOR="Blue"]Dim[/COLOR] rngHistory [COLOR="Blue"]As[/COLOR] Range
    
    [COLOR="Blue"]Set[/COLOR] shHistory = Sheets("History")
    [COLOR="Blue"]Set[/COLOR] shCurrent = Sheets("Current")
    
    [COLOR="Blue"]With[/COLOR] shHistory
        [COLOR="Blue"]Set[/COLOR] rngHistory = .Range("A1", .Range("A1").End(xlDown))
    [COLOR="Blue"]End[/COLOR] [COLOR="Blue"]With[/COLOR]
    
    [COLOR="Blue"]With[/COLOR] shCurrent
        [COLOR="Blue"]For[/COLOR] i = 1 [COLOR="Blue"]To[/COLOR] .Range("A1").End(xlDown).Row
            [COLOR="Blue"]If[/COLOR] WorksheetFunction.CountIf(rngHistory, .Cells(i, "A")) > 0 [COLOR="Blue"]Then[/COLOR]
                shHistory.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0) = .Cells(i, "A")
            [COLOR="Blue"]End[/COLOR] [COLOR="Blue"]If[/COLOR]
        [COLOR="Blue"]Next[/COLOR]
    [COLOR="Blue"]End[/COLOR] [COLOR="Blue"]With[/COLOR]

[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Sub[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,224,606
Messages
6,179,862
Members
452,948
Latest member
UsmanAli786

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