Deleting values on various sheets

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,199
Office Version
  1. 2007
Platform
  1. Windows
Hi,
I have a command button of which when run it will delete certain cell value on different worksheets.
The worksheets are all in the same workbook called ACCOUNTS

The below code is what ive done so far BUT im stuck with the code that fits where you see CODE GOES HERE
The part which i always get wrong where to tell the code to plly the deletion to what sheet



Rich (BB code):
Private Sub ClearSheetValues_Click()
Dim answer As Integer
answer = MsgBox("THIS WILL CLEAR ALL CELL VALUES" & vbNewLine & vbNewLine & "ON ALL WORKSHEETS" & vbNewLine & vbNewLine & "CLICK YES TO CONTINUE", vbYesNo + vbCritical, "ACCOUNTS CLEAR VALUES MESSAGE")
If answer = vbNo Then
  Exit Sub
Else
End If

CODE TO GO HERE

End Sub

REFERENCE BELOW FOR WHICH SHEETS / CELLS NEED TO BE DELETED

INCOME (1}

Range("A4:G28").SpecialCells(xlCellTypeConstants).ClearContents
Range("B1:C1").SpecialCells(xlCellTypeConstants).ClearContents

INCOME (2)

Range("A5:G28").SpecialCells(xlCellTypeConstants).ClearContents
Range("B1:C1").SpecialCells(xlCellTypeConstants).ClearContents
Range("C4:G4").SpecialCells(xlCellTypeConstants).ClearContents

INCOME (3)

Range("A5:G28").SpecialCells(xlCellTypeConstants).ClearContents
Range("B1:C1").SpecialCells(xlCellTypeConstants).ClearContents
Range("C4:G4").SpecialCells(xlCellTypeConstants).ClearContents

EXPENSES (1)

Range("B1:C1").SpecialCells(xlCellTypeConstants).ClearContents
Range("A4:K28").SpecialCells(xlCellTypeConstants).ClearContents

EXPENSES (2)

Range("A5:K28").SpecialCells(xlCellTypeConstants).ClearContents
Range("B1:C1").SpecialCells(xlCellTypeConstants).ClearContents
Range("D4:K4").SpecialCells(xlCellTypeConstants).ClearContents

EXPENSES (8)
Range("A5:K28").SpecialCells(xlCellTypeConstants).ClearContents
Range("B1:C1").SpecialCells(xlCellTypeConstants).ClearContents
Range("D4:K4").SpecialCells(xlCellTypeConstants).ClearContents

mileage (1)

Range("B1:D1").SpecialCells(xlCellTypeConstants).ClearContents
Range("A3:D29").SpecialCells(xlCellTypeConstants).ClearContents
Range("A34").SpecialCells(xlCellTypeConstants).ClearContents
 
Yes
It keeps showing the message for the first sheet

Did you use my code i posted to see if it worked for you,also uploaded a file of my workbook
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
See attached screenshots please.
 

Attachments

  • 192.jpg
    192.jpg
    30.1 KB · Views: 5
  • 193.jpg
    193.jpg
    37.5 KB · Views: 5
  • 194.jpg
    194.jpg
    157.3 KB · Views: 3
Upvote 0
In that case there is something different between the workbook your using & the one you uploaded.
You should not get that error.
 
Upvote 0
The workbook i upload is that of this one.

Did you try the one i uploaded ?
 
Upvote 0
Yes I did & it works fine, once the sheet name was corrected.
 
Upvote 0
Another test.
Please look at the before & after screen shots
I edited the range on the sheet INVOICE 1 like so A4:G28 to A4 and also the second line B1:C! to B1

For some reason it deletes cell value A1 and also cell vales of Row 3 ?????????
 

Attachments

  • 195.jpg
    195.jpg
    61.6 KB · Views: 3
  • 196.jpg
    196.jpg
    60.3 KB · Views: 3
Upvote 0
Post the actual code that you amended
A4:G28 to A4
B1:C1 to B1

I only altered this section.

Rich (BB code):
With ThisWorkbook.Sheets("INCOME (1)")
Application.EnableEvents = False
.Range("A4").SpecialCells(xlCellTypeConstants).ClearContents
.Range("B1").SpecialCells(xlCellTypeConstants).ClearContents
Application.EnableEvents = True
End With
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,202
Members
448,554
Latest member
Gleisner2

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