Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #10  
Old 07-15-2014, 06:35 AM
shilabrow shilabrow is offline HELP PLS: On Paste - Fire program to delete data below new records pasted Windows Vista HELP PLS: On Paste - Fire program to delete data below new records pasted Office 2007
Advanced Beginner
HELP PLS: On Paste - Fire program to delete data below new records pasted
 
Join Date: Apr 2014
Posts: 45
shilabrow is on a distinguished road
Default

Thanks excelledsoftware - I tried moving the code around as you suggested but not working - Below is a full revised version of line of code that you should be able to test with. I greatly appreciate your help. Thanks

Sub Report()
'IMPORTANT this code will DELETE data from a worksheet.
Dim c As Variant
Dim LastPasteRow As Long, FinalRow As Long, DataRows As Long

FinalRow = 30000 'Change this to the choice of final row of data.

On Error GoTo Clipboardempty
Range("A1").Select
ActiveSheet.Paste
On Error GoTo 0 'return errors back to normal.

'Run a loop to find the last row

For Each c In Selection
LastPasteRow = c.Row
Next c

DataRows = WorksheetFunction.CountA(Range(LastPasteRow + 1 & ":" & FinalRow))
If DataRows = 0 Then
End 'Ends the program because nothing is below
Else
'This is the command that deletes everything below.
Range(LastPasteRow + 1 & ":" & FinalRow).ClearContents
End If

'NEXT clean data to generate report
'To remove the * from the file
Sheets("DATA").Select
Range("QueryData").Select
Columns("F:F").Select
Selection.Replace What:="~*", Replacement:="", LookAt _
:=xlPart, SearchOrder:=xlByColumns, MatchCase:=False, SearchFormat:= _
False, ReplaceFormat:=False

'To Custom Sort the Subcategories in the right order needed in the Reports
ActiveWorkbook.Worksheets("DATA").Sort.SortFields. Clear
ActiveWorkbook.Worksheets("DATA").Sort.SortFields. Add Key:=Range("F:F"), _
SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:= _
"Banana,Apple,Tomatoes,Spices" _
, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("DATA").Sort
.SetRange Range("QueryData")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

'This refreshes all Pivot Table Element for Report
ActiveWorkbook.RefreshAll

'This is to autofit the sheet
Set mysheet = ActiveSheet
For Each Sheet In Worksheets
Sheet.Select
Cells.EntireColumn.AutoFit
Next Sheet
mysheet.Select
'To select the first cell
Sheets("Sort").Select

End

Clipboardempty:
'Checks if the clipboard is empty and if so halts execution
MsgBox "Nothing to paste, program ending."
End
End Sub
Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
HELP PLS: On Paste - Fire program to delete data below new records pasted Fire drop down Macro on change carlosriver24 Word 1 08-02-2012 07:18 PM
HELP PLS: On Paste - Fire program to delete data below new records pasted Conditional Formatting over copied and pasted data kb3264 Excel 6 07-11-2012 07:12 AM
HELP PLS: On Paste - Fire program to delete data below new records pasted Stop underlining pasted data LarryStroup PowerPoint 5 01-11-2012 12:47 PM
HELP PLS: On Paste - Fire program to delete data below new records pasted why when we copy and paste the "text box" then the pasted doesn't go to where the cur Jamal NUMAN Word 1 04-11-2011 03:54 AM
Ungrouping an object pasted from another program bracker PowerPoint 0 01-28-2011 11:11 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:13 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft