+ Reply to Thread
Results 1 to 4 of 4

Use variable to find and copy range with find function

  1. #1
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Use variable to find and copy range with find function

    So, I have the following piece of code that is searching a specific word and it should copy the range starting in the cell under it until last row. It returns an error on the line marked in red. I hope that someone may have an idea why and how to change it.

    Please Login or Register  to view this content.
    Thanks
    Click the * to say thanks.

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Use variable to find and copy range with find function

    Change the line in red to:
    Please Login or Register  to view this content.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Re: Use variable to find and copy range with find function

    Hi, Olly, many thanks, works like a charm. If I am not asking too muck, do you mind telling me the difference between them?

  4. #4
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Use variable to find and copy range with find function

    Your variable "cell" refers to a range object. You were trying to refer to it as a string.
    (incidentally, that's a very bad variable name, it's not a good idea to use reserved words as variables)

    We fixed this by defining the range with two range objects:
    Please Login or Register  to view this content.
    You could also fix it by referring to the range address, which is what you were trying to do initially, in which case the code would change to:
    Please Login or Register  to view this content.

    I'd also recommend qualifying the first Range object in your Set cell line, and changing the ActiveCell reference to a static range...

+ 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 Range with Find Function
    By rodgersmg in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-08-2015, 10:12 AM
  2. Range.Find function fails to find a match but For loop confirms that match exists
    By 6StringJazzer in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-08-2013, 03:35 PM
  3. using .find to then set a range as a variable
    By lgjmac in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-16-2013, 10:33 AM
  4. Replies: 6
    Last Post: 12-21-2012, 08:03 AM
  5. Looking up a variable using the Find function
    By Steve0492 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-07-2012, 04:18 PM
  6. [SOLVED] Find/Copy Variable length range
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-06-2006, 03:55 PM
  7. [SOLVED] Using Array variable in FIND function
    By GreenInIowa in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-01-2005, 04:09 PM

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