?
Solved

Macro needed to empty a cell based on two criteria

Posted on 2011-03-09
10
Medium Priority
?
238 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

719 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