Consulting

Results 1 to 12 of 12

Thread: Multi Criteria Macro

  1. #1

    Multi Criteria Macro

    Once again I am at a loss as how to start.

    My problem is in several parts:

    1 - Within range "Q11:W56" find rows where CellValue "U" > 0, then:
    A) Copy Value in Cell "U" to the same row Cell "AB"
    b) Clear Data in Row where CellValue "U" > 0

    2 - Copy Values in Range "Y11:AA11" to row where CellValue "U" > 0

    Problem 1:
    Some of the rows in the "Q11:W56" range may be blank.

    Problem 2:
    Data must be cleared (step 1A) must be executed before step 2.

    So much information on the forum, so little knowledge (on my part).

    As always, many thanks in advance.


    a

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    You don't specify where in the row the data is to be pasted.
    [VBA]Sub Test()
    Dim cel As Range
    For Each cel In Intersect(Range("U:U"), ActiveSheet.UsedRange)
    If cel > 0 Then
    cel.Offset(, 7) = cel
    cel.Offset(, -4).Resize(, 7).ClearContents
    Range("Y11:AA11").Copy cel.Offset(, 4) '<=====Change offset to suit
    End If
    Next
    End Sub
    [/VBA]
    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

    If only I communicated as well as you wrote code

    1 - Within range "Q11:W56" find rows where CellValue "U" > 0, then:
    A) Copy Value in Cell "U" where value > 0 to the same row Cell "AB"
    B) Clear range "Q:W" Data in Row where CellValue "U" > 0

    2 - Copy Values in Range "Y11:AA11" to row where CellValue "U" > 0

    Revised text = red

    It is important that the range for the code execution be limited to
    "Q11:W56"

    Many thanks (again) for the help.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sub Test()
    Dim cell As Range
    For Each cell In Range("Q11:Q56")

    If Cells(cell.Row, "U").Value > 0 Then

    Cells(cell.Row, "U").Copy Cells(cell.Row, "AB")
    cell.Resize(, 7).ClearContents
    Range("Y11:AA11").Copy cell.Offset(, 4) '<=====Change offset to suit
    End If
    Next
    End Sub
    [/vba]
    Last edited by mdmackillop; 03-27-2008 at 05:44 AM. Reason: typo corrected
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    XLD's mod is almost it. The only remaining problem is that the code
    Range("Y11:AA11").Copy cel.Offset(, 4)
    is not working, I get "Run-Time Error 424: Object Required"

    Again, What is required is that the Values in Range "Y11:AA11" are copied to the row where CellValue "U" > 0 (This would mean that if "U13" >0 then "Y11:AA11" is copied to "Y13:AA13")

    On another note, XLD, I traveled to Chile on business many times in the past. It is one of my absolute favorite countries.


    Many thanks

    a




  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Change cel to cell in the offending line.
    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'

  7. #7
    Doh!

    Thanks very much to all

    a

  8. #8

    ONE reaminig error

    Cells "U11:U56" are fomula. I need to copy the Values to "AB"

    Tried several mods, all of which did not work (or course).

    Thanks

    a

    ====================================

    Found the answer (I think).
    Cells(cell.Row, "AB").Value = Cells(cell.Row, "U")
    Trust this is correct implementation

    Thanks again to all..

    a
    Last edited by abesimpson; 03-27-2008 at 08:14 AM.

  9. #9
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    You can do them all at once
    [VBA]
    Cells(11, "AB").Resize(46).Value = Cells(11, "U").Resize(46).Value
    [/VBA]
    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'

  10. #10
    Sigh;

    Even when I think I'm getting smart I find it's just not up to scratch. LOL

    Thanks for the improvement.

    a

  11. #11
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    You're vey close though!
    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'

  12. #12
    "Close" counts in horseshoes and not much else. Nice of you to say so though.

    a

Posting Permissions

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