+ Reply to Thread
Results 1 to 5 of 5

Automatically copying rows from one sheet to another based upon criteria in column B

  1. #1
    Registered User
    Join Date
    07-25-2015
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    22

    Automatically copying rows from one sheet to another based upon criteria in column B

    I have a worksheet with all of my entries, called "all" (sheet 2):
    Column A: date
    Column B: Pymt (such as "Amex", "Visa" or a number for a check, etc)
    Column C: Amount
    Column D: Vendor
    Column E: Notes
    Column F: Job
    Column G: Category (such as "Commissions", "Materials" etc)

    I would like sheet 4, called "Amex" to automatically populate rows A:G with column B payments that are Amex, as I add them to "all" throughout the year. (As well as the other pymt types on their respective sheets)

    I have used a database in the past to accomplish this, but I have a bad "delete" trigger finger and want to avoid databases. You can only protect-lock the delete/insert rows and columns, not cells. I found this VB script somewhere else, but I must not understand it because it didn't work The sample was for someone else's worksheet, but I only changed my sheet and range names. Could someone help me out?

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Columns("B:B")) Is Nothing Then Exit Sub

    If Target.Value = "Amex" Then
    Range(Range("A" & Target.Row), Range("G" & Target.Row)).Copy _
    Sheets("Amex").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)


    End If

    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    06-29-2014
    Location
    Australia
    MS-Off Ver
    MSO 365
    Posts
    1,098

    Re: Automatically copying rows from one sheet to another based upon criteria in column B

    Hello SLBell,

    Try the following adjustment to your code:-

    Please Login or Register  to view this content.
    Your sheet names need to be spelt exactly as per the entries in Column B for the code to work. Perhaps using a drop down in each cell in Column B would be a good idea to prevent spelling errors.

    I hope that this helps.

    Cheerio,
    vcoolio.

  3. #3
    Registered User
    Join Date
    07-25-2015
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Automatically copying rows from one sheet to another based upon criteria in column B

    Thank you so much for replying! For some reason, nothing happened when I entered a test entry. I changed "sheet" to "Amex" and nothing happened either. I have attached a very pared down spreadsheet, so you can see what I am trying to accomplish. [The dashboard (sheet 1) is obviously messed up now, I'm not worried about it because my full workbook is OK.] I really appreciate your help!
    Suzanne
    https://www.dropbox.com/sh/notaqk42m...lV4GfTcxa?dl=0

  4. #4
    Valued Forum Contributor
    Join Date
    06-29-2014
    Location
    Australia
    MS-Off Ver
    MSO 365
    Posts
    1,098

    Re: Automatically copying rows from one sheet to another based upon criteria in column B

    Hello SLBell,

    Good news. I've implemented the code into the sample that you supplied and it works nicely. I don't know where you placed the code, but it needs to go into the worksheet module. So, right click on the "All" sheet tab and select "View Code" from the menu that appears. In the big white field that then appears, paste the code. I've made a minor adjustment to the code as follows so use this instead of the first one I supplied:-


    Please Login or Register  to view this content.
    The only differences are:-

    - I've declared a last column variable so, if you ever need to add more columns, you won't have to alter the code to suit.
    - I've added a Columns.AutoFit line of code. This will automatically fit the data nicely into each column in the sheets where the data is transferred to.

    I've attached your sample with the code implemented. I have tampered with your "All" sheet a little as you may notice. Each cell in Column B now has drop down boxes which will save you the task of typing in the type of payment. You can add to the list whenever necessary by using Data Validation. I have added another column for payment numbers more so to take care of the fact that you may receive payments by cheque thus all payments by cheque will be recorded in the "Chq" sheet.

    I hope that this helps.

    Cheerio,
    vcoolio.
    Attached Files Attached Files
    Last edited by vcoolio; 03-03-2017 at 11:16 PM.

  5. #5
    Valued Forum Contributor
    Join Date
    06-29-2014
    Location
    Australia
    MS-Off Ver
    MSO 365
    Posts
    1,098

    Re: Automatically copying rows from one sheet to another based upon criteria in column B

    Hello again SLBell,

    There appears to be some problem with opening the attachment (on my end at least) so below is a DropBox link to the sample file just in case:-

    https://www.dropbox.com/s/kfeeqoiu3c...l%29.xlsm?dl=0

    Cheerio,
    vcoolio.

+ 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. Automatically copy rows to another sheet based on criteria, when original sheet is updated
    By NoviceProgrammer in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-29-2016, 02:14 AM
  2. Automatically copying data into a new table based on 2 column criteria
    By gtdread in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 05-28-2014, 12:25 PM
  3. automatically copying rows to an existing spreadsheet based on criteria
    By Jocatlett in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-30-2013, 07:21 PM
  4. Copying rows in one sheet to another sheet based on defined criteria
    By arvin_tx in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-29-2012, 10:49 AM
  5. Copying rows from another sheet based on specific criteria
    By jamesbrown008 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-06-2011, 01:53 PM
  6. Replies: 0
    Last Post: 07-21-2010, 07:12 PM
  7. Copying an entire row or Rows based on column criteria
    By Bill in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 04-27-2005, 07:06 PM

Tags for this Thread

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