+ Reply to Thread
Results 1 to 4 of 4

Code not working - move rows when cell is less than zero

Hybrid View

wishmaker Code not working - move rows... 09-01-2011, 08:52 AM
Mordred Re: Code not working - move... 09-01-2011, 09:10 AM
Mordred Re: Code not working - move... 09-01-2011, 09:15 AM
Mordred Re: Code not working - move... 09-01-2011, 10:40 AM
  1. #1
    Registered User
    Join Date
    11-12-2009
    Location
    surrey
    MS-Off Ver
    Excel 2003
    Posts
    22

    Question Code not working - move rows when cell is less than zero

    Code updated with friends suggestion...

        Range("BU2").Select 
        Do Until Selection.Value = ""
             If Range("BU2").Value <= 0# Then 
              Rows("2:2").Copy
                Sheets("Queries").Select
                    Rows("1:1").Select
                    Selection.Insert Shift:=xlDown
                    Application.CutCopyMode = False
                Sheets("Just Giving").Select
                    Application.CutCopyMode = False
                    Selection.EntireRow.Delete
                Range("Bu2").Select 
                Else
                   Selection.Offset(1, 0).Select
             End If
          Loop
    ------------------------------------------------------------------
    I have been using the following code for last 2 years and it's worked fine. But I can't understand why it no longer works.

    Some background: I have a payment file with two sheets (Queires & Just Giving) the code is supposed to move any rows to the Queries sheet when the payment cell (BU2) is equal to or less than zero (<=)


        
    Range("BU2").Select
            Selection.Sort Key1:=Range("BU2"), Order1:=xlAscending, Header:=xlGuess, _
            OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
            DataOption1:=xlSortNormal 
    
    Range("BU2").Select 'BU
        Do While Selection.Value > 0
             If Range("BU2").Value <= 0 Then 'BU
              Rows("1:1").Copy
                Sheets("Queries").Select
                    Rows("1:1").Select
                    Selection.Insert Shift:=xlDown
                    Application.CutCopyMode = False
                Sheets("Just Giving").Select
                    Application.CutCopyMode = False
                    Selection.EntireRow.Delete
                Range("Bu2").Select 'BU
                Else
                   Selection.Offset(1, 0).Select
             End If
          Loop
    Last edited by wishmaker; 09-01-2011 at 10:33 AM.

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Code not working - move rows when cell is less than zero

    Hi wishmaker. When displaying code, we ask that you use code tags around your code as per rule #3. You have used html tags which are different. I will fix this for you but please remember to use code tags in the future.

    Thank you.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  3. #3
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Code not working - move rows when cell is less than zero

    The following gives me pause
    Do While Selection.Value > 0
         If Range("BU2").Value <= 0 Then
    where your criteria to step into the loop is if the selection "BU2" is greater than 0 and then inside the loop you want to copy the rows where "BU2" is less than or equal to 0. My understanding is that your if statement won't work because of your do while statement.

  4. #4
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Code not working - move rows when cell is less than zero

    If this is solved, please acknowledge the solution so that others will know if they should happen to peruse this thread.

    Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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