• Hide Duplicate Rows

    Author
    Topic
    #353565

    I

    Viewing 2 reply threads
    Author
    Replies
    • #517527

      I think the problem is your reference to ‘activecell’ – what happens if you change both of these to ‘cell’?

      Brooke

    • #517528

      From a quick test, and with the data selected, lRow is not incrementing – the comparison is always being made to the data in the first row…?

      • #517530

        Hiya,

        This worked for me

        Sub Hide_Dup_Rows()

        Dim lRow As Long
        Dim lRows As Long
        Dim lcol As Long
        Dim CurrRow As Long

        lRow = Selection.Row
        lRows = Selection.Rows.Count
        lcol = Selection.Column

        For CurrRow = lRow + 1 To lRow + lRows – 1
        If ActiveSheet.Cells(CurrRow, lcol).Value = ActiveSheet.Cells(CurrRow – 1, lcol).Value Then
        Rows(CurrRow).EntireRow.Hidden = True
        End If
        Next CurrRow

        MsgBox “done:”

        End Sub

        HTH
        Brooke

        • #517611

          Yes, it works. Thanks!
          Can you explain what is meant by the “long” in Dim lRow As Long?

          • #517662

            Sherry,

            Variables such as lrow can be defined as having a certain type – string or integer for instance. declaring them enables vba to work faster with them – if you don’t then it assigns the variable type variant, which takes slightly longer to work with. Each type of variable has it’s advantages and disadvantages. Very broadly speaking, the advantage is what it allows you to do and the disadvantage is the amount of memory declaring it as that type costs. Long is a numeric variable type that has the range (2,147,483,648) to 2,147,483,647 (to quote help). I would have declared lrow as type integer until about a year ago, but integer types only have a range from (32,768) to 32,768 – making it conceivable that you could (on occaision) run into problems in the routine under discussion – added to which, discussion in the lounge seems to indicate that integer really isn’t worth bothering with.

            In the absence of any other comments from others here who have a better grasp on these things than me, point vba help at the phrase ‘Data Type Summary’ – enter ‘data types’ in the index, click display and then look for ‘data type summary’.

            HTH

            Brooke

            • #517731

              Thanks! I’m still learning (as you can tell) and your feedback helped alot.

    • #517531

      Try this:

      Sub Hide_Dup_Rows()
      Dim oCell As Range
          For Each oCell In Selection
              If (oCell.Offset(-1, 0) = oCell.Value) Then
                  oCell.EntireRow.Hidden = True
              End If
          Next oCell
          MsgBox "done:"
      
      End Sub
      
    Viewing 2 reply threads
    Reply To: Hide Duplicate Rows

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: