+ Reply to Thread
Results 1 to 4 of 4

Need to be able to copy rows from a master sheet into another sheet

  1. #1
    Registered User
    Join Date
    07-17-2018
    Location
    Baltimore
    MS-Off Ver
    Office 2016
    Posts
    1

    Need to be able to copy rows from a master sheet into another sheet

    First I want to say, I know how to use Excel but never had much experience with VBA/macros and the experience I do have, is years old.
    I have a list of inventory - the two parts that really matter are the name and the location of the item. The items are alphebetized by name and new items are constantly being added. All of the items are on a master sheet, however we also have separate sheets for individual locations. What I want to do is run a macro where you can press a button and be able to automatically add the items to the location sheet corresponding to their location on the master sheet. Here is a simplified version of my inventory. (The screenshot is from a Mac, but I am working on Office 2016 for Windows.)

    Screen Shot 2018-07-17 at 9.40.37 PM.png

    Code is attached as a text file, but looks like this.

    Sub PopLoc_Click()

    Dim i As Integer
    i = 2 'Defines starting in Row 2


    Dim loc As String 'Location input will be a string
    loc = Sheets("Master Sheet").Cells(i, 2) ' Location initially starts in B2
    Sheets("Master Sheet").Range("B2").Activate

    Do Until Cells(i, 2).Value = ""
    If loc = "A" Then
    Sheets("Master Sheet").Range("A2:B2").Copy Sheets("A").Range("A2:B2")
    ElseIf loc = "B" Then
    Sheets("Master Sheet").Range("A2:B2").Copy Sheets("A").Range("A2:B2")
    ElseIf loc = "C" Then
    Sheets("Master Sheet").Range("A2:B2").Copy Sheets("A").Range("A2:B2")
    Else
    MsgBox ("Please select a valid location from the drop down menu for the Item in RowCount.")
    End If

    i = i + 1
    Loop

    MsgBox ("Finished!!!")
    MsgBox (i)

    End Sub


    As of now, it correctly places only the first row from my master inventory into the correct column as expected, but will not continue onto do the same for the next columns, and beyond that I'm not sure how to write it so that after one item is put on a location sheet, the next item that is added will be put onto the next free line. I suspect I am on the write track with what I already have (I know it's probably not elegant) because when the Message Box displays the number of rows it got down to, it displays 7, meaning it went through all of the rows but just didn't copy/paste any but the first.

    I apologize in advance if this is extremely stupid, and if the solution is simple, but I really just re-taught myself everything I know about VBA in 4 hours today and this is as far as I could get. Any help (with some explanation if possible) would be greatly appreciated.

    Honestly we should probably just move all our inventory to Access, but that is a change I think would be too big for others that use it to accept...
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Need to be able to copy rows from a master sheet into another sheet


    Easier just using a filter or an advanced filter per location …

  3. #3
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: Need to be able to copy rows from a master sheet into another sheet

    Hi, welcome to the forum

    1. Why would you upload a text file when you have already shown you have the excel file? Please provide the (CLEAN) excel file
    2. You probably dont need VBA for this, there are a few formula ways to do the same thing, automatically
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,516

    Re: Need to be able to copy rows from a master sheet into another sheet

    Looping is not the fastest way but if the file is not too big, it will at least do the job.
    I certainly would look into what the other gentlemen suggest.
    Please Login or Register  to view this content.

+ 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] Copy rows to master sheet based on contents in column
    By gjw1971 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-08-2017, 06:15 PM
  2. Copy and paste equal rows from master sheet to other sheets
    By Sasquatch2014 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-05-2017, 09:42 AM
  3. VB to copy rows under different headers from multiple sheets to a master sheet.
    By aryansaran2008 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-13-2015, 03:59 AM
  4. Replies: 1
    Last Post: 09-15-2014, 01:03 PM
  5. Replies: 1
    Last Post: 11-14-2013, 09:24 PM
  6. Copy rows from master sheet to other sheets based on criteria
    By spikeysas in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-07-2011, 04:28 AM
  7. Copy rows from a master sheet based on condition
    By Rohun Heesen in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-13-2011, 08:33 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