Tom Black
asked on
How do you clear contents from the smae multiple ranges on slected sheets in the workbook
I need to clear contents from several indentical cells on multiple sheets within the workbook. I have tried the union command but I am getting anywhere.
Select the sheets before selecting the range, then all sheets will be affected.
ASKER
It is only for select worksheets within the workbook
Range("c7:R7,V7").ClearCon tents
Range("c7:R7,V7").ClearCon
ASKER
I didn't understand the selecting of specific sheets and how the code will only work for those selected
For only certain worksheets.
For Each ws In Worksheets
Select Case ws.Name
Case "SheetNotToClear", "AnotherNotToClear" ' add names of sheets NOT to clear
' do nothing
Case Else
ws.Range("C7:R7, V7").ClearContents
End Select
Next ws
You don't need to list all the worksheet names if there's some other way to identify them, eg names all begin with 'Sales'.
ASKER
Range("c7:R7,V7").Select
Selection.ClearContents
Rows("8:8").Select
Range(Selection, Selection.End(xlDown)).Sel ect
Selection.Delete shift:=xlUp
The above is what I am wanting to do on select worksheets
Selection.ClearContents
Rows("8:8").Select
Range(Selection, Selection.End(xlDown)).Sel
Selection.Delete shift:=xlUp
The above is what I am wanting to do on select worksheets
Mine was not a code solution so go with imnorie.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Would you mine explaining the case function?
A select case compares a value against the criteria of each case and when it finds a match the for that that case is executed.
If there is no match and there's an 'Else' case then that code is executed.
I know that probably doesn't make much sense, I'm not very good with explanations.
You don't actually need to use it here, I just find that with this sort of thing it's easier than using some long If statement.
If there is no match and there's an 'Else' case then that code is executed.
I know that probably doesn't make much sense, I'm not very good with explanations.
You don't actually need to use it here, I just find that with this sort of thing it's easier than using some long If statement.
Even then it still has some limitations.
What ranges are you trying to clear?
One way would be to create an array of the addresses of all the ranges and loop through the worksheets.
Open in new window
This will clear the ranges on all worksheets but you can change so it's only specific worksheets.