+ Reply to Thread
Results 1 to 3 of 3

How can I find duplicate values in a column and then change the value of a cell?

Hybrid View

  1. #1
    Registered User
    Join Date
    07-06-2011
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2007
    Posts
    2

    How can I find duplicate values in a column and then change the value of a cell?

    Hey guys, I'm sorry for what I think is a very newbie question, but I'm not sure where else to ask, and I'm not even sure how to search for what I'm looking for. I'm looking to see if someone can tell me if this is possible, and if it is, where I should start looking to create it.

    I have a call reporting system that exports call records into an excel spreadsheet. There is a timestamp column in these reports. What I'm looking to do is have some sort of macro/programmatic function loop through every row in the report. When it finds a row that has the exact same date/time stamp as the row above it (and only the row above it... though I guess this wouldn't really matter because if the row wasn't directly above it, the time/date stamp would be different), I need to change the value in a cell. To give an example:

    07-06-11 12:22:38 PM | 24s call duration | type incoming
    07-06-11 12:22:38 PM | 24s call duration | type outgoing

    In the above scenario, I would need to change the word outgoing to the word voicemail. Is that possible to do?
    Last edited by Excelcod; 07-06-2011 at 02:22 PM.

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: How can I find duplicate values in a column and then change the value of a cell?

    Excelcod,

    Give this a try:
    Sub ChangeOutgoingToVoicemailMacro_for_Excelcod()
        
        Const TmDtCol As String = "A"   'The column containing the Time/Date stamps
        Const TypeCol As String = "C"   'The column containing the Type
        Const StartRow As Long = 2      'The row the data starts on (not the header row)
        
        Dim rngTimes As Range: Set rngTimes = Range(TmDtCol & StartRow + 1, Cells(Rows.Count, TmDtCol).End(xlUp))
        Dim TimeCell As Range, rngVM As Range
        For Each TimeCell In rngTimes
            If TimeCell.Value = TimeCell.Offset(-1, 0).Value Then
                If rngVM Is Nothing Then
                    Set rngVM = Cells(TimeCell.Row, TypeCol)
                Else
                    Set rngVM = Union(rngVM, Cells(TimeCell.Row, TypeCol))
                End If
            End If
        Next TimeCell
        If Not rngVM Is Nothing Then rngVM.Replace "outgoing", "voicemail"
        
    End Sub


    Hope that helps,
    ~tigeravatar

  3. #3
    Registered User
    Join Date
    07-06-2011
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: How can I find duplicate values in a column and then change the value of a cell?

    tigeravatar, next time you're in Georgia, I owe you a beer! That's EXACTLY what I needed. Thank you so much!

+ 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