Advertisement
Guest User

Delete

a guest
May 21st, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. Sub DeleteReceipts()
  2. 'macro to delete all sheets in workbook
  3. 'keep database sheet and one report sheet
  4.  
  5. Dim ChrisSheet As Worksheet 'declare worksheet variable
  6.  
  7. Application.DisplayAlerts = False 'switch off confirmation dialogue box
  8.  
  9. For Each ChrisSheet In ActiveWorkbook.Sheets 'loop through sheets in workbook
  10.  
  11. If ChrisSheet.Index > 6 Then 'if the Sixth sheet or greater
  12.  
  13. ChrisSheet.Delete 'delete the sheet
  14.  
  15. End If 'close if statement
  16.  
  17. Next ChrisSheet 'close loop
  18.  
  19. Application.DisplayAlerts = True 'switch confirmation dialogue box back on
  20.  
  21. End Sub
  22.  
  23. Sub deleterows()
  24.  
  25. Dim lastrow
  26. 'Finding the lastrow in Column A
  27.  
  28. lastrow = ThisWorkbook.Sheets(1).Range("A2:N50000").ClearContents
  29. lastrow = ThisWorkbook.Sheets(2).Range("A2:E50000").ClearContents
  30. lastrow = ThisWorkbook.Sheets(4).Range("A2:O50000").ClearContents
  31. 'Deleting the cell contain 1 in Column A
  32.  
  33. For i = lastrow To 2 Step -1
  34. 'Finding the cell which contain 1 in Column A
  35.  
  36. If ThisWorkbook.Sheets(1).Cells(i, 2) = "Number" Then
  37. ThisWorkbook.Sheets(1).Rows(i).EntireRow.Delete
  38. End If
  39.  
  40. Next i
  41. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement