Macro to delete all data before pasting in new stuff

jontyoc

Board Regular
Joined
Sep 3, 2012
Messages
52
Hi All

I am using Excel 2007 and have a simple enough macro to paste data in to another sheet - simple is what I do best. :)

Sub Macro1()
'
' Macro1 Macro
With Sheets("data")
.Range("B3").PasteSpecial xlPasteAll

End With
End Sub


I am wanting to change this so that before it pastes any data into B3 it will delete all data from B3:AE22.
I have had a look around and found plenty to help me delete full rows or worksheets but not just to delete the data in those cells.
Hope this makes sense.

Thanks
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Clearing the contents of or deleting a range on the worksheet will clear the clipboard, so PasteSpecial will fail, I'm afraid.
 
Upvote 0
darn n blast. of course it does!
is there no work around other than manually doing before I PasteSpecial?
 
Upvote 0
I currently do it this way without even thinking about it:
1 - delete the data in spreadsheet
2 - copy the data to be pasted
3 - hit my macro button and paste it.

So since I have feeling my team leaders wont always follow this by email, if I was to have a step by step instructions:
1. Press this button (macro to delete)
2. Copy data from source
3. Press this button (macro to paste)

Then it should do. I think asking them to press the two buttons may be fine and even the laziest will follow (hopefully!), whereas asking them to find and then delete the range from 8 different worksheets may not be.
 
Upvote 0
try this

select the data, then hit button

Code:
[COLOR=#333333]Sub Macro1()[/COLOR]
[COLOR=#333333]
     Sheets("data").Cells.Clear
     Selection.Copy
     Sheets("data")[/COLOR][COLOR=#333333].Range("B3").PasteSpecial xlPasteAll[/COLOR]
     Application.CutCopyMode = False



[COLOR=#333333]End Sub[/COLOR]
 
Last edited:
Upvote 0
try this

select the data, then hit button

Code:
[COLOR=#333333]Sub Macro1()[/COLOR]
[COLOR=#333333]     Sheets("data").Cells.Clear
     Selection.Copy
     Sheets("data")[/COLOR][COLOR=#333333].Range("B3").PasteSpecial xlPasteAll[/COLOR]
     Application.CutCopyMode = False
[COLOR=#333333]End Sub[/COLOR]

This should also work (note clear only the cells the OP mentioned in Message #1)...
Rich (BB code):
Sub Macro1()
     Sheets("data").Range("B3:AE22").Clear
     Selection.Copy Sheets("data").Range("B3")
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,968
Messages
6,175,677
Members
452,666
Latest member
AllexDee

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