+ Reply to Thread
Results 1 to 3 of 3

Need VBA Macro to make multiple totals based on value of a different cell.

  1. #1
    Forum Contributor
    Join Date
    02-26-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    173

    Need VBA Macro to make multiple totals based on value of a different cell.

    Hello! First, let me thank you for looking at my thread in an effort to help me. I appreciate it!

    I have a spreadsheet that looks similar to this spreadsheet.png but without the red values in column F. I want the macro to make the red totals (totals stay black, red is for clarification of what I want the macro to make.)

    I need make a macro that will sum the figures in column E into column F based on if the word in Range("A2:A" & Lrow) is "MN" or "URS" or "Other"
    I already have a function that calculates the last row of a transaction called Lrow. In this example, Lrow = 7

    Sometimes, there may be no rows with MN in the A column. Sometimes there may be no rows with URS in the A column. Sometimes there may be no rows for "Others" in the A column.

    Pseudocode:

    Dim groupMN as Integer
    Dim groupURS as Integer
    Dim groupOther as Integer
    Dim lastMN as String
    Dim lastURS as String
    Dim lastOther as String
    Dim rngA as Range

    Set rngA = Range("A2:A" & Lrow)

    For each Cell in rngA
    if Left(rngA, 2) = "MN" Then
    groupMN = groupMN + ColumnE.Cell.Value _
    lastMN = ColumnE.Cell.Address
    ElseIf Left(rngA, 3) = "URS" Then
    groupURS = groupURS + ColumnE.Cell.Value _
    lastURS = ColumnE.Cell.Address
    Else groupOther = groupOther + ColumnE.Cell.Value _
    lastOther = ColumnE.Cell.Address
    EndIf
    Loop

    if groupMN > 0 Range(lastMN).Offset(0,1).Value = groupMN
    if groupURS > 0 Range(lastURS).Offset(0,1).Value = groupURS
    if groupOther > 0 Range(lastOther).Offset(0,1).Value = groupOther
    Any help would be greatly appreciated!
    Last edited by smpita; 02-26-2014 at 08:13 PM.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Need VBA Macro to make multiple totals based on value of a different cell.

    Try this...

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Contributor
    Join Date
    02-26-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    173

    Re: Need VBA Macro to make multiple totals based on value of a different cell.

    Fantastic! Thank you AlphaFrog!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Need IF statement or Macro to make decision based on multiple criteria
    By weddica in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-25-2013, 03:30 PM
  2. Replies: 0
    Last Post: 03-08-2013, 06:34 AM
  3. How do I make a macro conditionally run based on the defined name of a cell
    By JTwrk in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-18-2012, 12:56 AM
  4. Create 2 Totals, One Based On Name And One Based On Name And Cell Fill Color
    By PIPPIBOOKS in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-20-2008, 04:41 PM
  5. [SOLVED] How to make a cell show totals
    By Don in forum Excel General
    Replies: 1
    Last Post: 08-04-2005, 09:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1