+ Reply to Thread
Results 1 to 9 of 9

Search Range, find criteria, offset, copy and paste to blank cell in new specified range

  1. #1
    Registered User
    Join Date
    02-12-2019
    Location
    West Yorkshire, UK
    MS-Off Ver
    2013
    Posts
    12

    Search Range, find criteria, offset, copy and paste to blank cell in new specified range

    Hi all,

    After some help. I'm wanting to search a column for a specific word (in my case "hol"). When I've found that word I would like to offset my column by one, cut the contents from that cell and then paste it as a value to the first available blank cell in a new range. I need this to do for every instance of my criteria.

    Now I believe i'm fine in finding the word, offsetting and copying all in a loop. its the looking for a free cell where i'm stuck.

    My range is E4:70 and I want to paste to range o42:o51
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    882

    Re: Search Range, find criteria, offset, copy and paste to blank cell in new specified ran

    Now I believe i'm fine in finding the word, offsetting and copying all in a loop. its the looking for a free cell where i'm stuck.
    Can we see your macro so we know where you are please?

    As a basic method to paste in the next row in your range then
    Please Login or Register  to view this content.
    but if there is any chance you could have more than would fit down to O51 then you need to put something in the code to handle it.
    If my solution worked (or not) please let me know. If your question is answered then please remember to mark it solved

    Computers are like air conditioners. They work fine until you start opening windows. ~Author Unknown

  3. #3
    Registered User
    Join Date
    02-12-2019
    Location
    West Yorkshire, UK
    MS-Off Ver
    2013
    Posts
    12

    Re: Search Range, find criteria, offset, copy and paste to blank cell in new specified ran

    Quote Originally Posted by WasWodge View Post
    Can we see your macro so we know where you are please?

    As a basic method to paste in the next row in your range then
    Please Login or Register  to view this content.
    but if there is any chance you could have more than would fit down to O51 then you need to put something in the code to handle it.
    i'm roughly here at the moment.

    Sub Format()
    '
    ' Format Macro
    '

    '

    Set Rng = Range("e4:e70")
    For Each cl In Rng
    If cl.Value = "hol" Or cl.Value = "sick" Then cl.Offset(, -1).Select
    Selection.Copy


    Next cl

    End Sub

  4. #4
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    882

    Re: Search Range, find criteria, offset, copy and paste to blank cell in new specified ran

    Personally I would use Find for the initial search but as you are dealing with a small range then it won't be an issue so
    Please Login or Register  to view this content.
    But the below could still be an issue...

    but if there is any chance you could have more than would fit down to O51 then you need to put something in the code to handle it.

  5. #5
    Registered User
    Join Date
    02-12-2019
    Location
    West Yorkshire, UK
    MS-Off Ver
    2013
    Posts
    12

    Re: Search Range, find criteria, offset, copy and paste to blank cell in new specified ran

    Quote Originally Posted by WasWodge View Post
    Personally I would use Find for the initial search but as you are dealing with a small range then it won't be an issue so
    Please Login or Register  to view this content.
    But the below could still be an issue...
    have tried this however I keep getting a run-time error 91: object variable or with block variable not set message. Any ideas?

    BTW your help is much appreciated.

  6. #6
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    882

    Re: Search Range, find criteria, offset, copy and paste to blank cell in new specified ran

    Not really if your workbook is the same as what you uploaded as I don't get the error (see the workbook uploaded below, click the button).
    All I can suggest is a) if you have any protection on the worksheet turn it off as that will produce an error b) upload the workbook that you are getting the error on with the code as you are running it so I can see it.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    02-12-2019
    Location
    West Yorkshire, UK
    MS-Off Ver
    2013
    Posts
    12

    Re: Search Range, find criteria, offset, copy and paste to blank cell in new specified ran

    Quote Originally Posted by WasWodge View Post
    Not really if your workbook is the same as what you uploaded as I don't get the error (see the workbook uploaded below, click the button).
    All I can suggest is a) if you have any protection on the worksheet turn it off as that will produce an error b) upload the workbook that you are getting the error on with the code as you are running it so I can see it.
    Unfortunately i'm not able to give you the spreadsheet i'm using due to confidentiality and all that...

    however on the debugger it highlights cl.Offset(, -1).Copy Range("O42:O51").Find("*", , xlValues, , xlByRows, xlPrevious)(2)

    could it be anything to do with the names actually being formulas on the original sheet?

  8. #8
    Registered User
    Join Date
    02-12-2019
    Location
    West Yorkshire, UK
    MS-Off Ver
    2013
    Posts
    12

    Re: Search Range, find criteria, offset, copy and paste to blank cell in new specified ran

    all sorted. In my new sheet I had no name at the start of where it was going to paste so it couldn't find a value to start with. I've just adjusted the range. Thankyou ever so much for all your help.

  9. #9
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    882

    Re: Search Range, find criteria, offset, copy and paste to blank cell in new specified ran

    Just in case you get any more issues try the below, it is a bit messier but forces it a bit
    Please Login or Register  to view this content.

+ 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. [SOLVED] Find if cell value is in range of other workbook and if true, copy-paste an offset cell
    By Szechter in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-18-2019, 01:54 PM
  2. VBA copy range of cells, paste on next blank cell down
    By ahalliwell in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-22-2018, 10:46 AM
  3. Find cells, copy range with criteria and paste with offset
    By benfontein in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 03-13-2017, 03:25 AM
  4. [SOLVED] Help! - Copy Range (Sheet1,A10:F50), Paste Range (Sheet 2,A1:F41), Offset Range & Repeat
    By cjtimmer in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 09-30-2015, 06:27 PM
  5. VBA code to copy cell formats and paste using offset for Rows/Range
    By spenlinhauer in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-12-2014, 07:45 PM
  6. Replies: 1
    Last Post: 02-04-2014, 01:57 PM
  7. [SOLVED] Find first non-blank cell after a group of blanks copy offset cells, find next blank, loop
    By gwsampso in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-21-2012, 06:11 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