+ Reply to Thread
Results 1 to 4 of 4

Need function to count rows until trigger, use variable to specify cell range to copy

  1. #1
    Registered User
    Join Date
    11-14-2010
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    2

    Angry Need function to count rows until trigger, use variable to specify cell range to copy

    I'm attempting to do two things in an Excel workbook, which I will believe require the use of at least one, if not two macros, but I'm clueless as to how to go about this.

    The first step is creating some sort of macro to count cells in one column. The count would always begin at the same cell (A17) of a sheet that will always be titled 'Segments'. The count should begin with a stored variable of 1, and add 1 for every subsequent cell in the column it checks that does not include the words 'Total Revenues'. When it reaches these words, the count should not add 1, and cease counting, saving the variable.


    The second step is using the number that the counting macro reached to output the content of the rows 17 to (17+n) into a separate sheet in the workbook. Similarly, I would like to be able to do this not just for column A, but for any number of columns. For example, rows 17 to 17+n for columns A, B, C and D will be copied to another sheet, becoming rows 7 to 7+n, for the same columns.

    Overall, the function will:

    a) Determine how many rows in Column A contain relevant data
    b) Export the data from several columns on the sheet to another parallel sheet, with the correct number of rows


    Strictly speaking, this operation could be done without the first step, if I was aware of how to do the second step, but have the number 'n', calculated by the macro, be replaced with a manually input number in a 'variable' cell.

    Either way, I'm clueless as to how to do this. Can anyone help? It would be much appreciated.

    Thanks in advance!
    Last edited by Iblis; 11-15-2010 at 04:09 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    06-17-2009
    Location
    Chennai,India
    MS-Off Ver
    Excel 2003,excel 2007
    Posts
    678

    Re: Tricky macro question

    QUOTE
    some sort of macro to count cells in one column
    UNQUOTE
    you need not require a macro. you can use countif function.

    e.g.suppose the date is from A1 to A30 and you need to start counting only from A17 then the formula will be
    =countif(A17:A30,"Total Revenues")
    if it is more than 3 you "save the variable" what is meant by saving the variable

    second problem not clear. do you want all the rows between 17 and 30(above example) are to be copied or only those rows where "total revenues" are there. clarify.

  3. #3
    Registered User
    Join Date
    11-14-2010
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Tricky macro question

    The second problem, to clarify, is that I want the rows counted, from A17 until the cell containing 'Total Revenues' to be copied into an equal number of rows on another sheet. The count function would allow Excel to determine how many rows there are to be copied, so it could identify the proper range of cells to copy.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Tricky macro question

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution. Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.
    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ 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