Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2006
    Posts
    1

    Unanswered: End If without block If error-Help

    I am having trouble running a macro. I want it to search a column and remove all duplicates. Everytime I run it, I get the "End If without block If" error. Any suggestions.....thanks in advance.

    code:

    Range("AF1:AF300").Select
    Selection.Sort Key1:=Range("AF1"), Order1:=xlAscending, Header:=xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
    ColNum = Selection(1).Column
    For RowNdx = Selection(Section.Cells.Count).Row To Selection(1).Row + 1 Step -1
    If Cells(RowNdx, ColNum).Value = Cells(RowNdx - 1, ColNum).Value Then Cells(RowNdx, ColNum).Value = ""
    End If
    Next RowNdx

    Selection.Sort Key1:=Range("AF1"), Order1:=x1Ascending, Header:=x1No, OrderCustom:=1, MatchCase:=False, Orientation:=x1TopToBottom

  2. #2
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    You don't need the End If after the row: If Cells(RowNdx, ColNum).Value = Cells(RowNdx - 1, ColNum).Value Then Cells(RowNdx, ColNum).Value = "" (since your then statement is on the same line).

    If you phrased it like this below, then you would need the End If

    If Cells(RowNdx, ColNum).Value = Cells(RowNdx - 1, ColNum).Value Then
    Cells(RowNdx, ColNum).Value = ""
    End If
    Last edited by pkstormy; 09-15-06 at 12:14.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

Posting Permissions

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