Results 1 to 6 of 6

If the ID appears once or twice add a 6 to column F

Threaded View

  1. #1
    Forum Contributor
    Join Date
    07-31-2012
    Location
    Los Angeles, USA
    MS-Off Ver
    2003, 2010, 365
    Posts
    320

    If the ID appears once or twice add a 6 to column F

    Hi,

    If the ID appears once or twice in Column A then add a 6 to column H, but if the ID appears 3 or more times in column A then do nothing.

    I would like to use VBA only for excel 2003 because it will be added to a larger VBA later.

    Thanks to Tigeravatar earlier I received the following code which works great for adding a 6 for each ID that appears.

    So if somebody could suggest a way to make only work for the ID appearing either less than 3 times, otherwise the value in column F should be 0.

    Sub tgr()
        
        Dim IDCell As Range
        Dim strUnq As String
        
        For Each IDCell In Range("A2", Cells(Rows.Count, "A").End(xlUp)).Cells
            If InStr(1, "||" & strUnq & "||", "||" & IDCell.Text & "||", vbTextCompare) = 0 Then
                Cells(IDCell.Row, "H").Value = 6
                strUnq = strUnq & "||" & IDCell.Text
            End If
        Next IDCell
    End Sub

    David
    Last edited by djfscouse; 03-21-2013 at 10:41 AM.

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