Solved

Macro needed to empty a cell based on two criteria

Posted on 2011-03-09
10
230 Views
Last Modified: 2012-05-11
See attached report.  Each month we need to empty the cell "Grand Total" on whatever row contains the word "Pending" is located on. In the spreadsheet example, there are 7 cells to empty. To make it interesting, the example attached only shows January.  Once February's data is added, then the "Grand Total" column moves one column to the right. to make room for the February data  Same will happen when we add March and so on.  Since I have 100 spreadsheets to remove this pending/Grand Total cell each month, is there a macro that can do this even as the spreadsheet grows?  Thanks for any help!  

  TestOpenedClosedPending.xls
0
Comment
Question by:SFrongillo
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 22

Expert Comment

by:rspahitz
Comment Utility
Hi SF.

I'm just wondering why you're not using formulas for things.  I realize you're trying to do some dynamic manipulation of the sheets, but if done right (like with named ranges), it will all work without having to deal with all of these other issues.

Do you want to explore that direction?  Otherwise I'll throw out some VBA code to assist with your task, but it will likely be more complex than some good formulas :)
0
 

Author Comment

by:SFrongillo
Comment Utility
Can you give me a little more info on the formula's method? I have over 100 spreadsheets that I need to open and remove the Pending -Grand Total cell for.
0
 
LVL 22

Expert Comment

by:rspahitz
Comment Utility
How is the data getting into the cell?  When I look, I see that it is already blank.
Are you saying that when you insert a column for February, you'd like the Pending for January to clear, or does the grand total somehow get a new value?
0
 
LVL 22

Expert Comment

by:rspahitz
Comment Utility
Just another thought...what if you pre-created the columns for each month, then hid them all until you needed then?
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Expert Comment

by:darcy_morse
Comment Utility
I would precreate the columns.  The field that you want to clear each time, I would name with a named range.  Then instead of searching for the pending, you could just reference that cell.
0
 

Author Comment

by:SFrongillo
Comment Utility
The sample is a Pivot created from data.  The pivot creates the totals for Open, Closed, Pending, however we want to remove the "Grand Total" from the Pending - since it is not needed (Pending for the month is actually the current total/snap shot for the YTD month).  Yes - the sample is blank to show just what I wanted to wipe out.  When we add Februarys data, the "Grand Total" column adds Jan + Feb data which is fine for the Open/Closed rows, but not for the pending.
0
 
LVL 8

Expert Comment

by:point_pleasant
Comment Utility
The below code will work on the sheet you provided.  It assumes that the word "Pending" will only appear in Col A thru D and that the last col of every row will be the grand total so no how many months you stick inbetween the last col will be the "Grand Total" and rows containg the word "Pending" will have the last column emptied.

Good Luck



Sub Remove_GT()
'
'Remove Gramd Total
'
   
' Count the # of occurances of "Pending" in Column A:D
    tmp1 = Application.WorksheetFunction.CountIf(Range("A:D"), "*Pending*")
   
    Dim LastCol As Integer
    Dim CurCol As Integer
    Dim CurRow As Integer
       
    Cells.Find(What:="Pending", After:=ActiveCell, LookIn:=xlValues, _
    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False).Activate
   
    'Start Loop
    For x = 1 To tmp1
      With ActiveSheet
        CurRow = ActiveCell.Row
        CurCol = ActiveCell.Column
        LastCol = .Cells(CurRow, .Columns.Count).End(xlToLeft).Column
        Cells(CurRow, LastCol).Select
        ActiveCell = "JUNK"
        Cells(CurRow, CurCol).Select
      End With
      Cells.FindNext(After:=ActiveCell).Activate
    Next
End Sub
0
 
LVL 8

Expert Comment

by:point_pleasant
Comment Utility
oops sorry replace the word JUNK with null value
0
 
LVL 22

Accepted Solution

by:
rspahitz earned 500 total points
Comment Utility
I would suggest 35095935 as the answer.

Also, to author, 35085881 was a good direction to go in.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

772 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

14 Experts available now in Live!

Get 1:1 Help Now