+ Reply to Thread
Results 1 to 6 of 6

Macro to add items with value to another tab

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-28-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 365
    Posts
    298

    Exclamation Macro to add items with value to another tab

    Hi there,

    Can you please help me building a macro that adds items with value in a list to a different tab?

    See attached Example spreadsheet demonstrating in more details.

    Thanks!
    Attached Files Attached Files

  2. #2
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Macro to add items with value to another tab

    I went with this macro assigned to the button:

    Option Explicit
    Public Sub AddItemsToList()
    
    Dim vC As Range
    Dim nR As Long
    
    nR = Worksheets("LIST").Cells(Worksheets("LIST").Rows.Count, "A").End(xlUp).Row + 1
    For Each vC In Range("E:E").SpecialCells(xlCellTypeConstants)
        With Worksheets("LIST").Cells(nR, "A")
            .Value = vC.Offset(0, -4).Value
            .Offset(0, 1).Value = vC.Value
        End With
        vC.Value = ""
        nR = nR + 1
    Next vC
    
    End Sub
    Also attached.

    WBD
    Attached Files Attached Files
    Office 365 on Windows 11, looking for rep!

  3. #3
    Forum Contributor
    Join Date
    07-28-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 365
    Posts
    298

    Re: Macro to add items with value to another tab

    Thanks WBD, but I'm having problems to implement it on my real sheet.

    I tried to reproduce my real spreadsheet with the attached new example, and you can see that after you run the macro, the items and the quantities are in different rows in the "New PO" tab. Can you help me fixing that?

    Also, when I have my real spreadsheet with all the data and formulas, this macro takes around 5 seconds to complete (counter productive when going through hundreds of items). Is there a way to make it faster? I have a similar macro that copy & paste and run super fast, but it does not look at blank cells. The code is:
    Sub MyAdd()
        Dim LastR As Range
        Set LastR = Sheets("new pos").Range("a" & Rows.Count).End(xlUp)(2)
        With Sheets(" P S I ")
            LastR.Resize(, 5).Value = Array(.[C6].Value, .[c7].Value, .[C31].Value, .[D31].Value, .[E31].Value)
            LastR.Range("T1").Resize(, 1).Value = Array(.[N100].Value)
            LastR.Range("AE1").Resize(, 3).Value = Array(.[N88].Value, .[N89].Value, .[N90].Value)
    
            .[C31:E31].ClearContents
        End With
    End Sub
    Attached Files Attached Files

  4. #4
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Macro to add items with value to another tab

    Try this instead:

    Public Sub AddItemsToList()
    
    Dim vC As Range
    Dim vD As Range
    Dim nR As Long
    
    Application.ScreenUpdating = False
    nR = Worksheets("New POs").Cells(Worksheets("New POs").Rows.Count, "B").End(xlUp).Row + 1
    If nR = 2 Then nR = 3
    Set vC = Worksheets(" P S I ").Range("B41:Y61")
    vC.AutoFilter
    vC.AutoFilter Field:=23, Criteria1:="<>"
    For Each vD In vC.Resize(, 1).SpecialCells(xlCellTypeVisible)
        If vD.Value <> "" Then
            Worksheets("New POs").Cells(nR, "B").Value = vD.Value
            Worksheets("New POs").Cells(nR, "C").Value = vD.Offset(0, 22).Value
            nR = nR + 1
        End If
    Next vD
    vC.AutoFilter
    vC.Resize(, 1).Offset(0, 22).ClearContents
    Application.ScreenUpdating = True
    
    End Sub
    WBD

  5. #5
    Forum Contributor
    Join Date
    07-28-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 365
    Posts
    298

    Re: Macro to add items with value to another tab

    It's almost good, but the clear contents line is giving me error because columns X and Y are merged.

    Interesting that your first macro did not have this error, so I'm wondering if it is possible to clear contents using the logic in the first code?

    Thank you!

  6. #6
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Macro to add items with value to another tab

    Change this one line to use 2 instead of 1:

    vC.Resize(, 2).Offset(0, 22).ClearContents
    WBD

+ 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] Macro to Copy Unique items i>e non duplicated items
    By Howardc1001 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-25-2022, 02:04 PM
  2. Macro to Match Items in Col C
    By Howardc1001 in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 05-27-2020, 12:20 PM
  3. [SOLVED] Macro to delete certain items then count remaining items #2
    By elgato74 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 12-21-2019, 02:26 PM
  4. [SOLVED] Macro to delete certain items then count remaining items
    By elgato74 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-14-2019, 03:20 PM
  5. [SOLVED] Macro to retain only certain items
    By flupsie in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-16-2017, 07:00 AM
  6. macro to filter all items in Autofilter except 2+ items
    By DanRiverBrew in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-09-2013, 09:15 PM
  7. Identify Items, Sort those Items, Copy the Items
    By a1981stingray in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-14-2010, 10:50 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