Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Macro needed to empty a cell based on two criteria

Posted on 2011-03-09
10
Medium Priority
?
241 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
9 Comments
 
LVL 22

Expert Comment

by:rspahitz
ID: 35085510
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
ID: 35085544
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
ID: 35085881
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 22

Expert Comment

by:rspahitz
ID: 35085905
Just another thought...what if you pre-created the columns for each month, then hid them all until you needed then?
0
 

Expert Comment

by:darcy_morse
ID: 35086517
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
ID: 35094988
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
ID: 35095935
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
ID: 35095960
oops sorry replace the word JUNK with null value
0
 
LVL 22

Accepted Solution

by:
rspahitz earned 2000 total points
ID: 35318163
I would suggest 35095935 as the answer.

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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…

564 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