+ Reply to Thread
Results 1 to 6 of 6

VBA Question- copying specific range if condition is met

  1. #1
    Registered User
    Join Date
    02-08-2013
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    3

    VBA Question- copying specific range if condition is met

    Alright, so I am fairly comfortable with basic macros (I use record feature often to make what I need), but I have run into something I am going to need some help on.

    I have attached a spreadsheet. The top row is the quarter that the date in row 3 is in.

    I would like to make something that will take a look at cell a2 in the "Report" sheet, and go through the columns in the "Data" sheet. If the column's first number matches a2 in "Report", then copy everything below it to the "Report" sheet (does not matter where, really). If the value at the top does not match the reference, then go to the cell at the top of the next column and repeat.

    Essentially, if "Report"!a2 is 2, then all data in the "Data" sheet under a 2 in the first row will appear in the "Report" sheet.

    Hopefully this is an easy one for you experts. Thank you all very much, and I look forward to being able to give back one day.
    Attached Files Attached Files

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,789

    Re: VBA Question- copying specific range if condition is met

    Hi dnblnd,

    Welcome to the forum

    For better understanding can you please show the expected output?


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Registered User
    Join Date
    02-08-2013
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: VBA Question- copying specific range if condition is met

    Quote Originally Posted by :) Sixthsense :) View Post
    Hi dnblnd,

    Welcome to the forum

    For better understanding can you please show the expected output?
    Certainly- thanks for the quick reply. The attached spreadsheet is an example. In the Q3 Report sheet, there is a "3" in a2, and so everything from the Data sheet that was under a 3 is now copied over to the Q3 Report sheet. As another example, I made a Q2 Report sheet. Here, a 2 is in a2, and everything from the data sheet that was under a 2 has been copied to this sheet.
    Attached Files Attached Files

  4. #4
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,789

    Re: VBA Question- copying specific range if condition is met

    Try the below code....

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-08-2013
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: VBA Question- copying specific range if condition is met

    Brilliant. Thank you so much.

    For those wanting to do something like this- I made one change to this code in the "if" line. It will look at the top row, match the reference, and then copy below it according to the code. Works perfectly. Thanks again!

    Please Login or Register  to view this content.

  6. #6
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,789

    Re: VBA Question- copying specific range if condition is met

    Glad it helps you and thanks for the feedback

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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