+ Reply to Thread
Results 1 to 7 of 7

Copy cells between two found instances of a different strings

Hybrid View

joevan1 Copy cells between two found... 09-01-2014, 09:19 PM
alansidman Re: Copy cells between two... 09-01-2014, 09:27 PM
millz Re: Copy cells between two... 09-01-2014, 09:28 PM
joevan1 Re: Copy cells between two... 09-01-2014, 09:30 PM
joevan1 Re: Copy cells between two... 09-01-2014, 09:28 PM
humdingaling Re: Copy cells between two... 09-01-2014, 09:32 PM
alansidman Re: Copy cells between two... 09-01-2014, 09:40 PM
  1. #1
    Registered User
    Join Date
    04-02-2013
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    28

    Copy cells between two found instances of a different strings

    Hi everyone,

    I'm trying to write a code that searches for instances of a string within a cell within a range, and then copies everything between that cell and the next instance of a different string.

    Sounds confusing, but essentially I have multiple ranges between a cell containing 'Posts:' and a cell containing 'Logged', and these ranges differ in size, but are always contained between these two cells.

    This is what I have so far:

    
    Sub Consolidate()
    
    Dim StrSearch As String
    Dim StrSearch2 As String
    Dim rng1 As Range
    Dim rng2 As Range
    Dim int1 As Integer
    
    StrSearch = "Posts:"
    StrSearch2 = "Logged"
    
           With Worksheets(1).UsedRange
           Set rng1 = .Find(StrSearch, LookIn:=xlValues, LookAt:=xlPart)
           Set rng2 = .Find(StrSearch2, LookIn:=xlValues, LookAt:=xlWhole)
           
           SampleCnt = Application.WorksheetFunction.CountIf(Sheets("Raw").Range("A:A"), "Logged")
           
           Do While i < SampleCnt
              Set int1 = rng2.Row - rng1.Row
              rng1.Activate
              Range(ActiveCell, rng1.Offset(int1)).Select
              Selection.Copy
              Sheets("Output1").Select
              Range("A65536").End(xlUp).Offset(1, 0).Select
              ActiveSheet.Paste
              Sheets("Raw").Select
              Set rng1 = .FindNext(rng1)
              Set rng2 = .FindNext(rng2)
              i = i + 1
          Loop
      End With
      
      End Sub
    But I keep getting a 'Compile Error: invalid qualifier', likely because the 'rng1.Row' output is not being treated as an integer.

    Is there a way around this?

    Thanks so much in advance for all your help.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2506 Win 11
    Posts
    24,791

    Re: Copy cells between two found instances of a different strings

    When you run the code and get the error, what line of code is highlighted when you click on debug?
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Copy cells between two found instances of a different strings

    Did not really look into whether your code tackles your problem, but to fix that problem, you can try just removing the Set.

    Set int1 = rng2.Row - rng1.Row
    You only use Set for object variables, such as Range, Worksheet, etc.
    多么想要告诉你 我好喜欢你

  4. #4
    Registered User
    Join Date
    04-02-2013
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: Copy cells between two found instances of a different strings

    yep, that was exactly the problem haha

    thanks so much for your help millz!!

  5. #5
    Registered User
    Join Date
    04-02-2013
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: Copy cells between two found instances of a different strings

    Hi alansidman,

    the line I get the error with is the

    Set int1 = rng2.Row - rng1.Row
    the first line of the loop. Which leads me to think that it doesn't like the rng2.Row variables.

  6. #6
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Copy cells between two found instances of a different strings

    Set int1 = rng2.Row - rng1.Row

    try without SET
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  7. #7
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2506 Win 11
    Posts
    24,791

    Re: Copy cells between two found instances of a different strings

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ 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 if two cells found
    By frank35 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-19-2013, 02:35 PM
  2. [SOLVED] Find various strings and copy the found string in column A of the row it appears in.
    By equanet in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-29-2012, 02:55 PM
  3. Replies: 4
    Last Post: 02-16-2012, 11:29 AM
  4. Comparing strings and counting instances in a complex datasheet
    By rpthoth in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-21-2011, 03:54 PM
  5. Calculation of instances a value is found in a series of cells
    By DSBTX in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 02-24-2006, 03:10 AM

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