+ Reply to Thread
Results 1 to 7 of 7

VBA - Finding the start of second data set in same Column

  1. #1
    Registered User
    Join Date
    06-18-2020
    Location
    Washington DC
    MS-Off Ver
    Office 365
    Posts
    6

    VBA - Finding the start of second data set in same Column

    The attached sample data file is below. I am writing a macro to copy each of the four data sets separately to a different sheet in a certain spot. Long story short - What i cant figure out is the best way or any way to be able to copy the data set below the first data set.

    What I've tried/Additional Info:

    I was using .Finds to look for a text string and returning whats above up to the starting location. For Example i know I always need to copy from B4 to Column E & the row number that right above the one that contains the text 'Total Sales' in Column A. For the Table below Last Quarter - Total Returns, I cant always find the correct row to start the copy. I cant use a static reference since sometimes total sales is Merged into two rows, sometimes not (Total Sales is taking two rows in Column H as in the sample data as an example). So LastRow1 - 2 would work if sales occupies on row but not work if its merged into two rows. Is there an easier way to find the start of the Returns Row for both the last quarter data set as well as the start of the data set for this quarter returns?


    This is my most recent attempt:

    Please Login or Register  to view this content.


    This however isnt working properly so why i am trying to find another way
    Please Login or Register  to view this content.
    I am also aware my style is fairly rudimentary as i am self taught from the internet and mainly what other people post on forums. Any constructive feedback is helpful.
    Attached Files Attached Files

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: VBA - Finding the start of second data set in same Column

    Hmm, I'd first start off by getting rid of merged ranges... These are notorious for making downstream process difficult.
    There are no benefit from them, other than visual fluff at final stage of report.

    It isn't clear to me, what your final result should look like. Can you post another sample with manually created output that you are after?
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Registered User
    Join Date
    06-18-2020
    Location
    Washington DC
    MS-Off Ver
    Office 365
    Posts
    6

    Re: VBA - Finding the start of second data set in same Column

    Yeah, I wish the input file was cleaner. Attached is the output file. Basically it is just creating a formatted version with specific headers that can be exported to ppt, as a picture, etc. I am just trying to automate the move process from input to the output. Sometimes it wont have prior quarter data or it wont have return data so the input can be all over the place. I learned some If Statement logic for VBA so i have that, just have to figure out how to move the data..
    Attached Files Attached Files

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: VBA - Finding the start of second data set in same Column

    So you just want the data portion, which is customer rows?

    I assume other region (Headers etc) are already set up prior to moving data over. As these have merged ranges that prevents copy/paste.

  5. #5
    Registered User
    Join Date
    06-18-2020
    Location
    Washington DC
    MS-Off Ver
    Office 365
    Posts
    6

    Re: VBA - Finding the start of second data set in same Column

    Exactly, it is just pasting the customer rows to the output tab on the left.

  6. #6
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    Re: VBA - Finding the start of second data set in same Column

    Is it possible to find the text "Total returns" to get the row number ?
    Please Login or Register  to view this content.
    I put a comment mark on your copy code line, just for test if the code select each range from the four ranges correctly.
    But the code will fail if for example the data looks something like this :
    Customer 1
    Customer 2
    Customer 3
    blank cell
    Customer 5
    Total returns

    The code will also fail if the text "Total returns" is in a merge cell from two columns (for example column A and column B).
    The code won't fail if the text is in a merge cell from multiple rows (for example row15 to row 20)
    And why I use LookAt:=xlPart, because I found that the text "Total Sales" in the sheet is with one space after the last character ---> "Total Sales "
    Last edited by karmapala; 06-19-2020 at 05:11 PM.

  7. #7
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: VBA - Finding the start of second data set in same Column

    Assuming structure remains same for "Paste Location"...

    There are other ways to do this, and I'm not particularly fond of using Find method. But keeping similar method as original and without altering worksheet structure...
    Please Login or Register  to view this content.
    See attached.
    Attached Files Attached Files

+ 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. Finding Start/End Dates and Times
    By sa1ntj0hn in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-28-2018, 07:12 AM
  2. Finding lowest in column after matching data in another column
    By tiempo1976 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-10-2017, 01:22 PM
  3. Looking to have data entered start new column each day
    By coryblaine in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 05-25-2016, 12:21 PM
  4. Need help in finding start and End Quarter
    By eon13 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-19-2014, 11:00 AM
  5. Compare 2 sets of data according to a Start and an End date column
    By salsawarren in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-26-2014, 08:15 AM
  6. [SOLVED] Finding the start of non-zero value
    By a_driga in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-31-2012, 12:05 AM
  7. VBA: Finding row to start at
    By Mike Winqvist in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-12-2007, 07:06 AM

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