Solved

Macro needed to empty a cell based on two criteria

Posted on 2011-03-09
10
231 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Update As Well As Add 6 39
Excel callender with date slider 5 27
the code is not looping through 11 36
min values in series 13 14
Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
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…
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.

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

26 Experts available now in Live!

Get 1:1 Help Now