+ Reply to Thread
Results 1 to 6 of 6

Adding in a multiplication function to an existing macro

Hybrid View

  1. #1
    Registered User
    Join Date
    07-24-2013
    Location
    Calgary, Canada
    MS-Off Ver
    excel 2013
    Posts
    14

    Adding in a multiplication function to an existing macro

    Hi All

    I have my macro working essentially how I would like it to. However, as an added convenience for myself and other potential users down the road (this is a work in progress, as I am relatively new to excel) I would like my existing macro to also take in to account multiple projects. Basically the macro as it stands filters for unique values and then adds these values up on another sheet. I would like however, for these values to be multiplied by the of consoles that need to be made.

    On sheet 1 I have a tile set up where I can enter the number of consoles to be made. I would like the totals on sheet 2 to be multiplied by that number. I have tried to do this with VBA but my skills are unforunately lacking.

    The Cell I would like to be variable is L10 on sheet 1. I would like the count columns on sheet 2 to be automatically multiplied by the number in L10 in the macro. Here is my code:

    Sub CONSOL()
    '
    ' CONSOL Macro
    '
    ' Keyboard Shortcut: Ctrl+Shift+I
    
        Application.ScreenUpdating = False
        Range("B5").Select
        Columns("B:B").AdvancedFilter Action:=xlFilterInPlace, Unique:=True
        Range("B:B,C:C").Select
        Range("C1").Activate
        Selection.Copy
        Sheets("Sheet2").Select
        Range("A2").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Sheets("Sheet1").Select
        Application.CutCopyMode = False
        Columns("B:B").AdvancedFilter Action:=xlFilterInPlace, Unique:=False
        Columns("D:D").Select
        Columns("D:D").AdvancedFilter Action:=xlFilterInPlace, Unique:=True
        Range("D:D,E:E").Select
        Range("E1").Activate
        Selection.Copy
        Sheets("Sheet2").Select
        Range("C2").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Sheets("Sheet1").Select
        Application.CutCopyMode = False
        Columns("D:D").AdvancedFilter Action:=xlFilterInPlace, Unique:=False
        Columns("F:F").Select
        Columns("F:F").AdvancedFilter Action:=xlFilterInPlace, Unique:=True
        Range("F:F,G:G").Select
        Range("G1").Activate
        Selection.Copy
        Sheets("Sheet2").Select
        Range("E2").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Sheets("Sheet1").Select
        Application.CutCopyMode = False
        Columns("F:F").AdvancedFilter Action:=xlFilterInPlace, Unique:=False
        Columns("H:H").Select
        Columns("H:H").AdvancedFilter Action:=xlFilterInPlace, Unique:=True
        Range("H:H,I:I").Select
        Range("I1").Activate
        Selection.Copy
        Sheets("Sheet2").Select
        Range("G2").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Sheets("Sheet1").Select
        Application.CutCopyMode = False
        Columns("H:H").AdvancedFilter Action:=xlFilterInPlace, Unique:=False
        Range("J3,K3").Select
        Range("K3").Activate
        Selection.Copy
        Sheets("Sheet2").Select
        Range("I4").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Sheets("Sheet1").Select
        Application.CutCopyMode = False
        Sheets("Sheet2").Select
        Application.ScreenUpdating = True
    End Sub
    Thanks so much

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Adding in a multiplication function to an existing macro

    Where on Sheet2 are the totals going?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    07-24-2013
    Location
    Calgary, Canada
    MS-Off Ver
    excel 2013
    Posts
    14

    Re: Adding in a multiplication function to an existing macro

    Right in the columns that are to be multiplied. B, D, F, H. Originally they were just going to reflect the compiled data from sheet one. But I would also like them to be multiplied by the number in L10 on sheet 1

  4. #4
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Adding in a multiplication function to an existing macro

    Here's your original code a bit cleaned up :

    Sub CONSOL()
    '
    ' CONSOL Macro
    '
    ' Keyboard Shortcut: Ctrl+Shift+I
    
    On Error Resume Next
    
        Application.ScreenUpdating = False
        Sheets("Sheet1").Columns("B").AdvancedFilter Action:=xlFilterInPlace, Unique:=True
        Sheets("Sheet1").Range("B:B,C:C").Copy Destination:=Sheets("Sheet2").Range("A2")
        Application.CutCopyMode = False
        Sheets("Sheet1").Columns("B").AdvancedFilter Action:=xlFilterInPlace, Unique:=False
        Sheets("Sheet1").Columns("D").AdvancedFilter Action:=xlFilterInPlace, Unique:=True
        Sheets("Sheet1").Range("D:D,E:E").Copy Destination:=Sheets("Sheet2").Range("C2")
        Application.CutCopyMode = False
        Sheets("Sheet1").Columns("D").AdvancedFilter Action:=xlFilterInPlace, Unique:=False
        Sheets("Sheet1").Columns("F").AdvancedFilter Action:=xlFilterInPlace, Unique:=True
        Sheets("Sheet1").Range("F:F,G:G").Copy Destination:=Sheets("Sheet2").Range("E2")
        Application.CutCopyMode = False
        Sheets("Sheet1").Columns("F").AdvancedFilter Action:=xlFilterInPlace, Unique:=False
        Sheets("Sheet1").Columns("H").AdvancedFilter Action:=xlFilterInPlace, Unique:=True
        Sheets("Sheet1").Range("H:H,I:I").Copy Destination:=Sheets("Sheet2").Range("G2")
        Application.CutCopyMode = False
        Sheets("Sheet1").Columns("H:H").AdvancedFilter Action:=xlFilterInPlace, Unique:=False
        Sheets("Sheet1").Range("J3,K3").Copy Destination:=Sheets("Sheet2").Range("I4")
        Application.CutCopyMode = False
        Sheets("Sheet2").Activate
        Application.ScreenUpdating = True
    End Sub
    Now, same question as Norie - do you want to have TOTALS or do you want each cell copied to sheet 2 be multiplied with sheet 1 cell L10 ?
    Your request isn't entirely clear
    Please click the * below if this helps

  5. #5
    Registered User
    Join Date
    07-24-2013
    Location
    Calgary, Canada
    MS-Off Ver
    excel 2013
    Posts
    14

    Re: Adding in a multiplication function to an existing macro

    Sorry about the lack of clarity. Most of the time the value in L10 will be 1, so the totals will be the same as they would be multiplied or not. On the rare occasion where there are multiple projects with the same totals, I would like the macro to multiply all of the values on sheet 2 by the number in L10 on sheet 1. What this macro is being used for is counting measurements of various wood cuts, filtering them, and combining like values on sheet 2. Occasionally there will be a project where the same measurements are used multiple times.

    I hope this helps.

  6. #6
    Registered User
    Join Date
    07-24-2013
    Location
    Calgary, Canada
    MS-Off Ver
    excel 2013
    Posts
    14

    Re: Adding in a multiplication function to an existing macro

    I figured it out.

    Simply made a separate sheet (hidden) where the calculations are done and adjusted the macro accordingly (thanks to JasperD for the help there, I am starting to get the hang of this vba stuff). Now if I can only get my sum formulas to not calculate for a zero value...

    I know this is the wrong forum and I'll find it myself eventually I'm sure...but if anyone want to give a very quick indication of how to not make a formula calculate if there's a zero value I would appreciate it.

    Thanks for the help guys.

+ 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. Adding Progress Bar to existing Macro...
    By Zoediak in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-28-2013, 04:32 PM
  2. [SOLVED] Adding code for pivot cache refresh within an existing function
    By beckdog in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-22-2013, 02:51 PM
  3. Adding IF function to existing (complex) Formula
    By NDRYNWA in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 04-24-2013, 06:56 AM
  4. Adding to an existing macro
    By dcargill in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-27-2012, 09:32 AM
  5. Adding Series to my existing VBA Macro
    By dan_hibiki in forum Excel Charting & Pivots
    Replies: 8
    Last Post: 05-24-2010, 05:54 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