Remove and Replace all information

nathandavies9

New Member
Joined
Nov 4, 2014
Messages
16
Hi All,

I have a code which is assigned to a button, when the button is pressed the below macro runs and selects and copies all information which has a figure in column H and pastes it into a new work sheet "ORDER REC"

I was wondering if there is a way of deleting all the information in "ORDER REC" when the button is pressed and re-pasting the updated information into the work sheet.

Code:
Sub Order()

    Dim ws As Worksheet
    Dim lr As Long
    Dim last As Long
    Dim i As Long


Application.ScreenUpdating = False
    For Each ws In Worksheets
        If ws.Name <> "ORDER REC" And ws.Name <> "SUMMARY SHEET" And ws.Name <> "MANUFACTURING TIMES" And ws.Name <> "ELSTEEL" And ws.Name <> "COPPER" Then
            lr = ws.Range("C" & Rows.Count).End(xlUp).Row
            last = Sheets("ORDER REC").Range("C" & Rows.Count).End(xlUp).Row
            ws.Range("A2:L" & lr).Copy Sheets("ORDER REC").Range("A" & last + 1)
        End If
    Next ws


    With Sheets("ORDER REC")
    last = .Range("C" & Rows.Count).End(xlUp).Row
        For i = last To 2 Step -1
            If .Range("H" & i) = "" Then
            .Range("H" & i).EntireRow.Delete
            End If
        Next i
    End With


Application.ScreenUpdating = True
Application.CutCopyMode = False


    Sheets("ORDER REC").Select '
    Range("k" & (Range("k" & Rows.Count).End(xlUp).Row) + 2) = "= Sum(" & Range("k2", Range("k" & Rows.Count).End(xlUp)).Address & ")"
    
        ActiveWorkbook.Worksheets("ORDER REC").SORT.SortFields.Clear
    ActiveWorkbook.Worksheets("ORDER REC").SORT.SortFields.Add Key:=ActiveCell. _
        Offset(0, 3).Range("A1:A23"), SortOn:=xlSortOnValues, Order:=xlAscending, _
        DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("ORDER REC").SORT.SortFields.Add Key:=ActiveCell. _
        Offset(0, 2).Range("A1:A23"), SortOn:=xlSortOnValues, Order:=xlAscending, _
        DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("ORDER REC").SORT
        .SetRange ActiveCell.Offset(-1, 0).Range("A1:L24")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
       
        End Sub
This is my current code any help would be greatly appreciated.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Add this before your first loop
Code:
Sheets("ORDER REC").cells.clear
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,924
Members
452,366
Latest member
TePunaBloke

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