• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA coding to clear contents from selected cells from selected worksheet

Ankur Kumar

New Member
Hi,


I want to clear from coloumn D6:D14 from sheet1 and B5:F5000 and H5:p5000 from sheet2 in one click, i am attaching a sample workbook with it please help me out.





Thanks in advance

Ankur
 

Attachments

  • Sample.xlsx
    18.2 KB · Views: 4
Just use Macro Recorder.

Base syntax from recorder.
Code:
    Range("D6:D14").Select
    Selection.ClearContents
    Range("H5:P5000").Select
    Selection.ClearContents

Now, you want to make sure that it references specific sheet. So you'd qualify Range() with Sheets... And eliminate Select/Selection.

Ex:
Code:
Sub Demo()
Sheets("Sheet1").Range("D6:D14").ClearContents
Sheets("Sheet2").Range("H5:P5000").ClearContents
End Sub
 
I want to add some text as when i hit on clear button it show a message before clear the content like "clear all contents from selected cells" and then "continue to clear" when i hit on ok then clear the contents.
 
Yes , that's i need to do but i want to add this button in ribbon as when i click on excel option and customize ribbon and selecting macros from choose commands from then it is not showing there, please help
 
Back
Top