+ Reply to Thread
Results 1 to 8 of 8

Macro/VBA Copy several values from 1 row into new sheet with multiple rows

  1. #1
    Registered User
    Join Date
    08-22-2021
    Location
    Portugal
    MS-Off Ver
    Excel 2021 Mac
    Posts
    78

    Macro/VBA Copy several values from 1 row into new sheet with multiple rows

    Hi guys,
    I am using Office 2021 Mac on MPB with OS Monterey.

    I have an excel where I have a single row for each of my main items. To the right I have calculated my re-packed 1, 2, 4, 8, 16 once items with the new price (see attachment tab MainItem).

    For each main item and packaging size I need to create a single row in a new tab on the same excel (see attachment tab LoadItem).

    On the new tab I have the main item with packing size 01, 02, 04, 08, 16 added and the associated price.

    I want to use this new tab to update the sales prices of all my items in Quickbooks.

    Can somebody suggest a macro or VBA I could use to create my load file?

    Thanks in advance.
    Gerd
    Attached Files Attached Files

  2. #2
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: Macro/VBA Copy several values from 1 row into new sheet with multiple rows

    Hi Gerd,

    Try below code, though I think your expected results isn't all correct
    Please Login or Register  to view this content.
    If I was able to help, you can thank me by clicking the * Add Reputation under my user name

  3. #3
    Registered User
    Join Date
    08-22-2021
    Location
    Portugal
    MS-Off Ver
    Excel 2021 Mac
    Posts
    78

    Re: Macro/VBA Copy several values from 1 row into new sheet with multiple rows

    Thank you very much for the VBA. And it sure IS working correctly.

    I have 800+ items with their respective sales prices in the ItemLoad tab.

    I applied the VBA to my main price list and make the necessary VBA changes. But I would need 2 more small changes.

    1) I separate my main items groups with a blank row.
    2) The last record in my Excel has value Totals in cell A.

    I wanted to change the VBA To do the loop till it finds value Totals in A(X, 1), and skip any blank rows. My VBA changes trigger an error, I think my For statement is not allowed.

    Would you mind having a look at my changes?

    Thanks,
    Gerd

    Sub UpdateSalesPrice()

    Dim a
    a = Sheets("MainItem").[A1].CurrentRegion

    ReDim b(1 To UBound(a) * 5, 1 To 3)
    ' For X = 7 To UBound(a)
    For X = 7 To (a(X, 1) = "Totals") ' Checks for value Totals in cell A
    If a(X, 1) <> "" Then ' Skips blank row
    For y = 14 To 18
    i = i + 1
    b(i, 1) = a(X, 2) & Format(a(6, y), "00")
    b(i, 2) = a(X, 5) & " " & a(6, y) & "oz"
    b(i, 3) = a(X, y)
    Next
    End If
    Next

    With Sheets("ItemLoad").[A1].Resize(, 3)
    .Parent.UsedRange.Clear
    .Value = [{"QB Item","Description","Sales Price"}]
    .Offset(1).Resize(i) = b
    End With

    End Sub

  4. #4
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: Macro/VBA Copy several values from 1 row into new sheet with multiple rows

    I made few changes based on my understanding, if that's not what you're looking for, please post another sample file
    Please Login or Register  to view this content.
    PS: Please edit your post #3, select the VBA code then press the # button from the menu to insert code tags for you

  5. #5
    Registered User
    Join Date
    08-22-2021
    Location
    Portugal
    MS-Off Ver
    Excel 2021 Mac
    Posts
    78

    Re: Macro/VBA Copy several values from 1 row into new sheet with multiple rows

    I should have copied a sample of my main price list (see attached sample excel)

    I get an error where we assign the item number

    Sub UpdateSalesPrice()

    ' Dim a
    ' a = Sheets("MainItem").[A1].CurrentRegion

    Dim a, Lr As Long
    With Sheets("MainItem")
    Lr = .Range("A" & Rows.Count).End(xlUp).Row - 1
    a = .[A1].Resize(Lr, 8)
    End With

    ReDim b(1 To UBound(a) * 5, 1 To 3)
    For x = 7 To UBound(a)
    If a(x, 1) <> "" Then
    For y = 14 To 18
    i = i + 1
    b(i, 1) = a(x, 2) & Format(a(6, y), "00"). '<== This is where I get the error
    b(i, 2) = a(x, 5) & " " & a(6, y) & "oz"
    b(i, 3) = a(x, y)
    Next
    End If
    Next

    With Sheets("ItemLoad").[A1].Resize(, 3)
    .Parent.UsedRange.Clear
    .Value = [{"QB Item","Description","Sales Price"}]
    .Offset(1).Resize(i) = b
    End With

    End Sub
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    08-22-2021
    Location
    Portugal
    MS-Off Ver
    Excel 2021 Mac
    Posts
    78

    Re: Macro/VBA Copy several values from 1 row into new sheet with multiple rows

    After I have 18 columns in the excel I changed this statement. The sample I had provided only had 8 columns.

    a = .[A1].Resize(Lr, 18)

    But still get the error

  7. #7
    Registered User
    Join Date
    08-22-2021
    Location
    Portugal
    MS-Off Ver
    Excel 2021 Mac
    Posts
    78

    Re: Macro/VBA Copy several values from 1 row into new sheet with multiple rows

    I exited the excel then went back in. That seemed to have resolved my error.

    With this VBA everything is working now.

    Thanks again for your examples. I learned a lot.


    Sub UpdateSalesPrice()

    ' Dim a
    ' a = Sheets("MainItem").[A1].CurrentRegion

    Dim a, Lr As Long
    With Sheets("MainItem")
    Lr = .Range("A" & Rows.Count).End(xlUp).Row - 1
    a = .[A1].Resize(Lr, 18)
    End With

    ReDim b(1 To UBound(a) * 5, 1 To 3)
    For x = 7 To UBound(a)
    If a(x, 1) <> "" Then
    For y = 14 To 18
    i = i + 1
    b(i, 1) = a(x, 2) & Format(a(6, y), "00")
    b(i, 2) = a(x, 5) & " " & a(6, y) & "oz"
    b(i, 3) = a(x, y)
    Next
    End If
    Next

    With Sheets("ItemLoad").[A1].Resize(, 3)
    .Parent.UsedRange.Clear
    .Value = [{"QB Item","Description","Sales Price"}]
    .Offset(1).Resize(i) = b
    End With

    End Sub

  8. #8
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: Macro/VBA Copy several values from 1 row into new sheet with multiple rows

    Glad to help

    If that takes care of your question, please take a moment & mark this thread as [SOLVED] from the Thread Tools above your first post. Also, since you're new to the forum, you can thank those who have helped by clicking the little star icon under their usernames to * Add Reputation

+ 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 copy rows from multiple sheets to one sheet
    By MacroNovice2 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-19-2019, 10:45 AM
  2. [SOLVED] Macro to copy rows 1:6 to a new workheet after active sheet and paste only values.
    By catscats11 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-23-2018, 04:33 PM
  3. [SOLVED] Macro to Copy multiple rows from one sheet to another based on cell values
    By ParisG in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-13-2016, 03:07 AM
  4. [SOLVED] Macro to Copy Rows to new sheet based on Multiple Criteria
    By ecubersax in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-07-2015, 01:07 AM
  5. Replies: 3
    Last Post: 03-31-2014, 01:00 PM
  6. Replies: 1
    Last Post: 05-11-2013, 02:58 AM
  7. Search for Multiple String Values on Multiple Sheets and Copy Rows to New Sheet
    By rrtikker in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-15-2012, 12:21 PM

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