Solved

Clearing Cells

Posted on 2011-02-23
8
294 Views
Last Modified: 2012-05-11
EE Professionals,

I have a set of cells that I want to clear or "reset" with a Macro.  Currently I was looking at using;
Sub clearstrategicpriorities()
Dim i As Integer
With Worksheets("Strategic_Priorities")
    .Range("A4:D43").ClearContents
End With
End Sub

The problem is that the Cells have formulas in them so I don't want to use "clearcontents".  What can I use as a command that will allow me to clear the text out of the cells or reset them, without disturbing the formulas?

Thank you,

b.
0
Comment
Question by:Bright01
  • 4
  • 4
8 Comments
 
LVL 37

Expert Comment

by:Neil Russell
ID: 34959313
The formulas display results. How can you clear the DISPLAYED results but not the formula? I dont quite understand your aim?

If you have a forula in a cell it will display the result

What are you aiming to do?
0
 

Author Comment

by:Bright01
ID: 34959439
OK..... Here's the story; I just looked at what I was trying to do based on your comments.  I don't really need to delete the cells that have the formulas in them.  I must clear the contents of the cell that forces the text (that the formulas pull in) to clear.  So here's the issue, When I use my macro;

Sub clearstrategicpriorities()
Dim i As Integer
With Worksheets("Strategic_Priorities")
    .Range("B1").Delete
    .Range("A4:A43").ClearContents
    .Range("C4:C43").ClearContents
End With
End Sub

The Range(B1).Delete statement causes problems. If I simply go to the cell and backspace the Text out of B1, I have no problems.  So I think I need another word other than Delete or Clear Contents.....

Does that make sense?

B.
0
 
LVL 37

Expert Comment

by:Neil Russell
ID: 34959462
Can you upload an example sheet with comments on what you need to achieve?

.Range("B1").ClearContents sounds like ALL you need to me IF THAT is the cell that the others are pulling the text from.
0
 

Author Comment

by:Bright01
ID: 34959666
I was afraid you'd ask that!  Yep..... "the beast" is attached.  So, save a copy, than do three things;

1.) Use the drop down box to select one of three industries.  You will see that the Text changes based on the industry selected.
2.) I have a really cool Macro that puts a drop down box only where/when text is evident (Col. A and C).... you can see it when you change Industries (H,M.L).
3.) If you hit reset, it screws up the entire sheet and you even lose the list box.

What I'm trying to do is to reset the Industry (which removes the text) without losing the ability to "auto-resize" and also remove the sensitive list boxes (Col. A and C) until a new industry is selected.  

B.
Clearcontents-macro.xlsm
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 37

Expert Comment

by:Neil Russell
ID: 34961982
Chabge the formula in B4 to be...

=IF(OR(ISBLANK(B1), ISERROR(Priority_Formulas!E4) ),"",INDEX(PriorityDB!$E:$E,MATCH(Strategic_Priorities!$B$1&Priority_Formulas!E4,INDEX(PriorityDB!$A:$A&PriorityDB!$B:$B,0),0)))

And then change your code in module 1 to be......




Sub clearstrategicpriorities()
Dim i As Integer
    Application.EnableEvents = False
   
    With Worksheets("Strategic_Priorities")
        .Range("B1").ClearContents
        .Range("A4:A43").ClearContents
        .Range("C4:C43").ClearContents
    End With
    Application.EnableEvents = True
End Sub




Try that.
0
 
LVL 37

Accepted Solution

by:
Neil Russell earned 500 total points
ID: 34962042
Sorry I forgot the validations....

 
Sub clearstrategicpriorities()
Dim i As Integer
    Application.EnableEvents = False
    Application.ScreenUpdating = False
    With Worksheets("Strategic_Priorities")
        .Range("B1").ClearContents
        .Range("A4:A43").ClearContents
        .Range("A4:A43").Validation.Delete
        .Range("C4:C43").ClearContents
        .Range("C4:C43").Validation.Delete
    End With
    Application.ScreenUpdating = True
    Application.EnableEvents = True
End Sub

Open in new window

0
 

Author Comment

by:Bright01
ID: 34968015
On a flight from Beijing....will try this on Friday when I land.

Thank you!
0
 

Author Closing Comment

by:Bright01
ID: 35043345
Neil,

Excellent!  It worked!  I am terribly sorry for not getting back with you sooner.  This travel is killing me but hey "the life we choose"!  Anyway, very nice work Neil.

Best regards,

B.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We were having a lot of "Heartbeat Alerts" in our SCOM environment, now "Heartbeat" in a SCOM environment for those of you who might not be familiar with SCOM is a packet of data sent from the agent to the management server on a regular basis, basic…
The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now