Consulting

Results 1 to 8 of 8

Thread: Copy Ranges between sheets with Cycles

  1. #1

    Copy Ranges between sheets with Cycles

    Im searching for solution on how to populate blocks 1,2,3,4,7,9 with values from cache sheet (SQL query) where ranges change vertically. I'm stuck on this problem for a long time.

    Until cache sheet columns vertically changes (up/down) , i can't just use straight range copy/paste methods. I believe there's a great solution with Cycles
    More details in attachment NeedCycle.xlsx

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Using SUMPRODUCT
    Attached Files Attached Files
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Thank you. That's good but not for me. i need using cycles over the macro, cause i need to keep sheet CALC clear.

  4. #4
    It's not fair to ask same question to many sites

    https://www.ozgrid.com/forum/forum/h...ro-over-cycles

  5. #5
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I'll leave you to tidy up the formatting

    Sub Test()
        Set wss = Sheets("CALCcache")
        Set wst = Sheets("CALC")
        arr = Array(1, 2, 3, 4, 7, 9)
        With wss
            For a = 0 To 2
                Set strt = .Range("A:A").Cells.Find(arr(a), after:=.Cells(Rows.Count, 1), searchdirection:=xlNext)
                Set endd = .Range("A:A").Cells.Find(arr(a), after:=.Cells(Rows.Count, 1), searchdirection:=xlPrevious)
                rws = 2 + endd.Row - strt.Row
                Set tgt = wst.Cells(1, 1).Offset(, 7 * a)
                Range(strt, endd).Resize(, 6).Copy tgt
            Next a
    
    
            For a = 3 To 5
                Set strt = .Range("A:A").Cells.Find(arr(a), after:=.Cells(Rows.Count, 1), searchdirection:=xlNext)
                Set endd = .Range("A:A").Cells.Find(arr(a), after:=.Cells(Rows.Count, 1), searchdirection:=xlPrevious)
                Set tgt = wst.Cells(1, 1).Offset(rws, 7 * (a - 3))
                Range(strt, endd).Resize(, 6).Copy tgt
            Next a
        End With
    End Sub
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  6. #6
    Impressive. Thank you very much mdmackillop. Could you please exclude ID and Date from result set after macro is done.

    it works fast and great, and i want to figure out how to change result location of the on the sheet. For example: I need to locate blocks 1, 2, 3, 4 straight over 1 column. Block 9 under block 1 and block 7 under block 4?

  7. #7
    I have figured out with location. I played with .offset and got it Thank you very much.
    Now my problem is definitely SOLVED

  8. #8
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I played with .offset and got it
    Best way to learn! You can mark this solved using Thread Tools.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •