+ Reply to Thread
Results 1 to 15 of 15

help changing repeating code into array of somekind also copy highlighted rows to new shee

  1. #1
    Registered User
    Join Date
    10-01-2014
    Location
    Tx
    MS-Off Ver
    2013
    Posts
    50

    help changing repeating code into array of somekind also copy highlighted rows to new shee

    I am repeating the following code many times for varying cell contents. I know there must be a better way. I tried to change the code to array myself but apparently I was not doing something correctly. I am new to this (duh.lol)! I found the code in a forum and changed highlight cell to highlight entire row because the next step is to copy all rows in which are highlighted to a new sheet within the same workbook. Also the cell contents the code is searching for can be anywhere in column A thru M on any given row on the active sheet. I have Excel 2013 and am running Windows8.1.
    1. Should I use variant array, string array, named range(no clue how to do but have read about it), or another function?
    2.Could you please point me in the right direction as to how to copy highlighted rows to a new sheet?
    3.Lastly, should I be highlighting the entire row or just the active cells(as that is all I need) in the needed row? .
    Your help is very appreciated!!!

    Please Login or Register  to view this content.
    Again thank you for taking the time to read my ramblings and helping me!
    Last edited by baby_kay_2003; 10-22-2014 at 10:55 AM.
    baby_kay_2003

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: help changing repeating code into array of somekind also copy highlighted rows to new

    I think what you were trying to achive was something like this. I set it as variant so that you can easily add strings but if you wanted to define the size of the array you could just the same set it as a string.

    Untested:
    Please Login or Register  to view this content.
    Note: I am not sure how the wild card is going to work in the array.

  3. #3
    Registered User
    Join Date
    10-01-2014
    Location
    Tx
    MS-Off Ver
    2013
    Posts
    50

    Re: help changing repeating code into array of somekind also copy highlighted rows to new

    That is working until it gets to a value in the array for which there is not a match then it ends the sub instead of continuing to search.

    This is where I have been getting confused: You set it as variant so I could add strings. What does this mean? How would this be used?

    Do I need to define the size of the array? You do mean the columns the value could possibly be in correct?

    The wildcard is working very well

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: help changing repeating code into array of somekind also copy highlighted rows to new

    Another approach?

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-01-2014
    Location
    Tx
    MS-Off Ver
    2013
    Posts
    50

    Re: help changing repeating code into array of somekind also copy highlighted rows to new

    Thank you. That one works. but I have to do it twice because i have 2 types of data I am looking for. Is this what you would do?

    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: help changing repeating code into array of somekind also copy highlighted rows to new

    Yes, that's what I would do.

  7. #7
    Registered User
    Join Date
    10-01-2014
    Location
    Tx
    MS-Off Ver
    2013
    Posts
    50

    Re: help changing repeating code into array of somekind also copy highlighted rows to new

    Thanks to the both of you! Any chance I could also get help with the second part of my question? How to go about coping the highlighted cells and pasting into a new sheet?

  8. #8
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: help changing repeating code into array of somekind also copy highlighted rows to new

    Maybe:

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    10-01-2014
    Location
    Tx
    MS-Off Ver
    2013
    Posts
    50

    Re: help changing repeating code into array of somekind also copy highlighted rows to new

    I must be doing something wrong. I have tried everything I can think of and looked online to get the above code to work because I know it is something I am doing but I cannot get it to stop getting errors. Everything I have tried only gives a new error.

  10. #10
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: help changing repeating code into array of somekind also copy highlighted rows to new

    Did you create a Sheet named "New Sheet"? Or did you intend for the macro to create it?

  11. #11
    Registered User
    Join Date
    10-01-2014
    Location
    Tx
    MS-Off Ver
    2013
    Posts
    50

    Re: help changing repeating code into array of somekind also copy highlighted rows to new

    Yes I added a line of code to add the new sheet and used its name in the "new sheet". It creates the new sheet but it stays blank.
    Please Login or Register  to view this content.
    I can however get this code to work but only if it is saved in the workbook modules not in my personal or if I label the sheet name but I cannot use the sheet name because the sheet name changes each week. I do not know what causes this and cannot figure out how to fix it.

    this works in workbook module only:
    Please Login or Register  to view this content.
    This will work in personal but I need to use sheet code name:
    Please Login or Register  to view this content.

  12. #12
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: help changing repeating code into array of somekind also copy highlighted rows to new

    Maybe try:

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    10-01-2014
    Location
    Tx
    MS-Off Ver
    2013
    Posts
    50

    Re: help changing repeating code into array of somekind also copy highlighted rows to new

    Has anyone ever told you that you are amazing!!!!! I would have put money down that I tried that but I guess I didnt do it correctly. Thank you so much this has been driving me crazy! AGAIN you are wonderful!!!!

  14. #14
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: help changing repeating code into array of somekind also copy highlighted rows to new

    Welcome. Always glad to help out. Good to hear you have a solution to your problem.

  15. #15
    Registered User
    Join Date
    10-01-2014
    Location
    Tx
    MS-Off Ver
    2013
    Posts
    50

    Re: help changing repeating code into array of somekind also copy highlighted rows to new

    I have marked as solved and added reputation. Thanks again!

+ 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. Copy Highlighted Rows to another sheet
    By MBCMDR in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-07-2016, 08:56 AM
  2. [SOLVED] copy all highlighted rows to new sheet in order
    By cfinch100 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-22-2014, 02:21 PM
  3. Replies: 0
    Last Post: 11-12-2013, 04:56 PM
  4. [SOLVED] VBA Code: copy relative array formula into X rows
    By haven83 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-30-2012, 01:46 AM
  5. copy highlighted rows from Auto filter
    By tahirawan11 in forum Excel General
    Replies: 1
    Last Post: 06-19-2008, 12:00 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