+ Reply to Thread
Results 1 to 9 of 9

delteting rows via macro

Hybrid View

  1. #1
    Registered User
    Join Date
    07-05-2012
    Location
    Ontario, Canade
    MS-Off Ver
    Excel 2010
    Posts
    88

    delteting rows via macro

    I was just looking for some help with my macro,

     
    Range("V16").Select
        Range(Selection, Selection.End(xlDown)).Select
        Do Until ActiveRange.Value = ""
            If ActiveRange.Value <> "1" Then
                ActiveRange.EntireRow.Delete
            Else
                ActiveRange.Offset(1, 0).Select
            End If
        Loop
    End Sub
    I have a parameter set up basically if the data doesnt meet specifications then i want it to delete the entire row. the values found start at V16 and proceed down to V324. but V324 could change at anytime.

    also, for some reason my if function wont work. I ve tried re writing it, manipulating the sings etc. but to no avail. Here it is:

    =If(0.7<=A17<=3,1,"")

    thanks for the help!

  2. #2
    Forum Contributor day92's Avatar
    Join Date
    04-20-2010
    Location
    Los Angeles
    MS-Off Ver
    Excel 360
    Posts
    600

    Re: delteting rows via macro

    Mike take a look at this thread and see if it helps..

    http://www.excelforum.com/excel-gene...-column-a.html

  3. #3
    Registered User
    Join Date
    07-05-2012
    Location
    Ontario, Canade
    MS-Off Ver
    Excel 2010
    Posts
    88

    Re: delteting rows via macro

    thats where i got the code from lol, I just started playing around in vba in excel, so im still learning

  4. #4
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: delteting rows via macro

    I'm assuming you used day92's code from the thread he points to since they look so similar. In case you missed it, the Selection.End(xlDown) is likely screwing you up.

    Looks like you are combining two questions into one thread. In the future please ask as separate questions since it will help people find solutions to similar problems. As for your problem, you are thinking too much like a mathematician. Excel can't calculate a range of values in that way. You have to use =IF(AND(A17<=3, A17>=0.7),1,"").

    Pauley

  5. #5
    Forum Contributor day92's Avatar
    Join Date
    04-20-2010
    Location
    Los Angeles
    MS-Off Ver
    Excel 360
    Posts
    600

    Re: delteting rows via macro

    Try this..
    =IF(AND(A17>=0.7,A17<=3),1,"")

    If you are still having issue please upload some sample data with expected results.

  6. #6
    Registered User
    Join Date
    07-05-2012
    Location
    Ontario, Canade
    MS-Off Ver
    Excel 2010
    Posts
    88

    Re: delteting rows via macro

    thanks pauly,

    I eraased that line and it works well, Only thing is It isnt running after the: Do until ActiveRange.Value= ""

    Do i put anything in the quotes? and the rows that do = one in the Range i want to fill in blue. how would you do that?

    Would it be a Formating cmd?

  7. #7
    Valued Forum Contributor
    Join Date
    08-29-2011
    Location
    Mississauga, CANADA
    MS-Off Ver
    Excel 2010
    Posts
    503

    Re: delteting rows via macro

    Would you like to try this code
    Sub DeleteRows()
    Dim i As Long
    With ActiveSheet
        For i = .Range("V" & .Rows.Count).End(xlUp).Row To 2 Step -1
            If .Range("V" & i).Value <> "1" Then .Rows(i).Delete
        Next
    End With
    End Sub
    Regards,
    Khaled Elshaer
    www.BIMcentre.com

    Remember To Do the Following....
    1. Thank those who have helped you by clicking the Star below their post.
    2. Mark your post SOLVED if it has been answered satisfactorily:
    • Select Thread Tools (on top of your 1st post)
    • Select Mark this thread as Solved

  8. #8
    Registered User
    Join Date
    07-05-2012
    Location
    Ontario, Canade
    MS-Off Ver
    Excel 2010
    Posts
    88

    Re: delteting rows via macro

    Work Like a charm, Is there a way to leave the first 3 rows? thanks ALOT!

  9. #9
    Valued Forum Contributor
    Join Date
    08-29-2011
    Location
    Mississauga, CANADA
    MS-Off Ver
    Excel 2010
    Posts
    503

    Re: delteting rows via macro

    Sub DeleteRows()
    Dim i As Long
    With ActiveSheet
        For i = .Range("V" & .Rows.Count).End(xlUp).Row To 4 Step -1
            If .Range("V" & i).Value <> "1" Then .Rows(i).Delete
        Next
    End With
    End Sub

+ 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