+ Reply to Thread
Results 1 to 15 of 15

Vba macro to multiply and re arrrange data

Hybrid View

  1. #1
    Registered User
    Join Date
    03-07-2014
    Location
    london
    MS-Off Ver
    Excel 2016
    Posts
    83

    Vba macro to multiply and re arrrange data

    HI all

    the attached file


    contains 2 tabs

    1.R_Jetwash
    2.R_Jetwash_table


    1.R_Jetwash contains two areas where the user populates the data A to N and Q TO AB ( (please take into account that the number of rows can increase substantially)

    A TO N are volumes(sales) and Q to AB are prices

    what the macro has to do is to calculate the revenue (volume *price) in each site per month

    For example Revenue in Jan 18 in site 32 =

    4000 ( tab=R_Jetwash cell= c12)*0.83 ( tab=R_Jetwash cell= Q12) =332


    2. R_Jetwash_table

    this tab will show the result of each site in each month




    (the macro below is very similar, the difference is that has a tab called volumes, that tab was another factor to multiply in the above calculation. that tab is no longer in use in the above example
    perhaps you can use it as a reference. if it is confusing you please ignore it)



    Sub MakeTable()
        Dim vol     As Variant
        Dim con     As Variant
        Dim tbl     As Variant
        Dim i       As Long
        Dim j       As Long
        Dim iRow    As Long
        Dim dic     As Object
    
    
        With ThisWorkbook
            With .Worksheets("VOLUMES")
                vol = .Range("A2").Resize(.Cells(.Rows.Count, "A").End(xlUp).Row, 5)
            End With
            With .Worksheets("R_Jetwash")
                con = .Range("A1").Resize(.Cells(.Rows.Count, "A").End(xlUp).Row, 28)
            End With
        End With
        
        Set dic = CreateObject("Scripting.Dictionary")
        For i = 1 To UBound(vol)
            dic(vol(i, 2) & "|" & vol(i, 4)) = vol(i, 5)
        Next
        
        ReDim tbl(1 To UBound(con) * 12, 1 To 4)
        For i = 1 To UBound(con) - 1
            For j = 3 To 14
                iRow = (i - 1) * 12 + j - 2
                tbl(iRow, 1) = con(i + 1, 1)
                tbl(iRow, 2) = con(1, j)
                tbl(iRow, 3) = con(i + 1, 2)
                tbl(iRow, 4) = dic(con(i + 1, 1) & "|" & con(1, j)) * con(i + 1, j) * con(i + 1, j + 14)
            Next
        Next
    
    
        Application.ScreenUpdating = False
        With ThisWorkbook
            With .Worksheets("R_Jetwash_table")
                .Cells.Clear
                .Range("A1:D1") = Array("Site", "Month", "Jetwash", "Amount")
                .Range("A2").Resize(UBound(tbl, 1), UBound(tbl, 2)) = tbl
                .Columns("B:B").NumberFormat = "mmm-yy"
                .Columns("D:D").NumberFormat = "_-* #,##0_  -;-* #,##0_  -;_-* ""-""?_-;_-@_-"
                .Columns("A:D").EntireColumn.AutoFit
            End With
        End With
    End Sub
    Attached Files Attached Files
    Last edited by antonio32; 08-10-2017 at 09:10 AM. Reason: SOLVED

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2406 (Windows 11 23H2 64-bit)
    Posts
    82,320

    Re: Vba macro to multiply and re arrrange data

    Attach your workbook directly here, please.

    Unfortunately the attachment icon doesn't work at the moment, so to attach an Excel file you have to do the following: just before posting, scroll down to Go Advanced and then scroll down to Manage Attachments. Now follow the instructions at the top of that screen.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    03-07-2014
    Location
    london
    MS-Off Ver
    Excel 2016
    Posts
    83

    Re: Vba macro to multiply and re arrrange data

    i tried to attach a file of 2.70 mb xlsb it keeps failing. i have corrected the link it should work ok now
    Last edited by AliGW; 08-09-2017 at 05:49 AM. Reason: Unnecessary quotation removed.

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2406 (Windows 11 23H2 64-bit)
    Posts
    82,320

    Re: Vba macro to multiply and re arrrange data

    Cut the workbook down to just what we need to see to help you, then attach it again. A small, sample dataset will do. Many members will not access files via file-sharing sites.

  5. #5
    Registered User
    Join Date
    03-07-2014
    Location
    london
    MS-Off Ver
    Excel 2016
    Posts
    83

    Re: Vba macro to multiply and re arrrange data

    Quote Originally Posted by AliGW View Post
    Cut the workbook down to just what we need to see to help you, then attach it again. A small, sample dataset will do. Many members will not access files via file-sharing sites.
    the file is 9.40 kb now and your web says not file chosen, before was also within the size limits advised and was saying failing

    any solutions?

  6. #6
    Registered User
    Join Date
    03-07-2014
    Location
    london
    MS-Off Ver
    Excel 2016
    Posts
    83

    Re: Vba macro to multiply and re arrrange data

    i tried xlsx the file is 10kb same errir "no file chosen".....

    also tried xlsm.. "no file chosen"...

    can you help me with the question? the web seems not be working properly ..

    thanks in advance

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2406 (Windows 11 23H2 64-bit)
    Posts
    82,320

    Re: Vba macro to multiply and re arrrange data

    Try saving as .xlsx or .xlsm and attach.

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2406 (Windows 11 23H2 64-bit)
    Posts
    82,320

    Re: Vba macro to multiply and re arrrange data

    It's working fine for me - it's either something your end or you are not following the instructions for upload correctly.

  9. #9
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Vba macro to multiply and re arrrange data

    Hi,

    The workbook you have linked to on your first post has 39 worksheets and many 21 modules. The sheets are hidden. This is why the file is so big.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  10. #10
    Registered User
    Join Date
    03-07-2014
    Location
    london
    MS-Off Ver
    Excel 2016
    Posts
    83

    Re: Vba macro to multiply and re arrrange data

    Apologies now is attached, it was not the size. it was attaching ok i was not familiar with the layout of the web. Attached now

  11. #11
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Vba macro to multiply and re arrrange data

    Hi Antonio,

    It looks to me like you want a Pivot Table, that I've done on your second sheet, to sum the dollars. No VBA needed! Time to learn about Pivot Tables? See if my work makes sense to you and search the new for Pivot Table examples if needed.

    Car Wash Pivot Date Columns.xlsm

  12. #12
    Registered User
    Join Date
    03-07-2014
    Location
    london
    MS-Off Ver
    Excel 2016
    Posts
    83

    Re: Vba macro to multiply and re arrrange data

    HI Marvin

    i think you missread my post !

    what needs to be created is A1:C19 in R_Jetwash_table

    in order to create A1:C19 you need to multiply each volume per site by its price.

    that's the macro that i need

    (the values in A1:C19 they didn't calculate by themsleves )


    thanks in advance

    AC

  13. #13
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Vba macro to multiply and re arrrange data

    Hi Antonia,

    You are correct. I completely misunderstood your question. I think that giving the code from Jindon(?) with Scripting.Dictionary and a tab that wasn't there completely threw me off. See if what I've done in the attached is the steps you would go through to get your answer. If we can see the manual steps to do a problem, we can normally write a macro that does those manual steps. I've done two manual steps in the attached. I created a third table on the first sheet with a simple formula in yellow. Then I copies this third table and copied it using Values and Transpose. Will these manual steps answer your question?

    Antonio Jetwash product of tables.xlsm

  14. #14
    Registered User
    Join Date
    03-07-2014
    Location
    london
    MS-Off Ver
    Excel 2016
    Posts
    83

    Re: Vba macro to multiply and re arrrange data

    this is what i needed

    i found it but thanks anyway

    Sub xxx
    Dim Ray As Variant, n As Long, Ac As Long, c As Long
    Ray = Sheets("R_Jetwash").Range("A1").CurrentRegion.Resize(, 28)
    ReDim nray(1 To UBound(Ray, 1) * UBound(Ray, 2), 1 To 3)
    For n = 2 To UBound(Ray, 1)
    For Ac = 3 To 14
    c = c + 1
    nray(c, 1) = Ray(n, 1)
    nray(c, 2) = Ray(1, Ac)
    nray(c, 3) = Ray(n, Ac) * Ray(n, Ac + 14)
    Next Ac
    Next n
    Sheets("R_Jetwash_table").Range("A2").Resize(c, 3) = nray
    End Sub

  15. #15
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Vba macro to multiply and re arrrange data

    I'm so glad you found an answer for this one. It had me completely stumped. I really didn't want to read the code in your first post and figure it out after it really didn't work on your workbook. Being "close" to what you wanted was a real problem.

    If you have an answer to this problem, could you edit the first post and mark the thread as "Solved".

    Thanks

+ 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. macro to multiply tabs
    By swfarm in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-07-2017, 02:53 AM
  2. A macro to always multiply a cell by 10
    By smsmworld in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-30-2017, 03:26 PM
  3. Macro multiply rows and copy exact same data from original row
    By AlexAXL in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-02-2016, 06:46 AM
  4. Macro to multiply a fix value
    By buchumang in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-09-2014, 02:58 PM
  5. Replies: 4
    Last Post: 01-10-2014, 09:32 AM
  6. If criteria match, multiply then sum across multiply worksheets
    By ciayers in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-09-2013, 02:20 PM
  7. Excel macro to multiply by same value
    By Recycler29 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 10-12-2005, 07: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