Consulting

Results 1 to 11 of 11

Thread: Edit Cells By Comparing Value

  1. #1
    VBAX Regular
    Joined
    May 2015
    Posts
    27
    Location

    Edit Cells By Comparing Value

    Please Help, I have attached the doc.
    What im looking for is for the cells highlighted in yellow to have a msg of NH if the date (D.O.H.) is greater than cell B4. Any help is greatly appreciated, thank you.
    I can do it excel function but would like it done in VBA. Thanks again.
    Attached Files Attached Files

  2. #2
    VBAX Expert mperrah's Avatar
    Joined
    Mar 2005
    Posts
    744
    Location
    Sub probation90()
    Dim x, lr, c As Long
    
    lr = Cells(Rows.Count, 3).End(xlUp).Row
    c = 0
        For x = 11 To lr
            If Cells(x, 3).Value > Cells(4, 2).Value Then
            Cells(x, 4).Value = "NH"
            c = c + 1
            End If
        Next x
        MsgBox ("There are " & c & " NH employees as of " & Now())
    End Sub
    similar to last post

  3. #3
    VBAX Expert mperrah's Avatar
    Joined
    Mar 2005
    Posts
    744
    Location

    attached modified file

    vba52574.xlsm
    from excel type Alt+F8 then choose "probation90" and click run

  4. #4
    VBAX Regular
    Joined
    May 2015
    Posts
    27
    Location
    Thank you that does work but is there a way to make it auto populate without Alt+F8

  5. #5
    VBAX Expert mperrah's Avatar
    Joined
    Mar 2005
    Posts
    744
    Location
    Add this to the worksheet code
    and doubleclick any where to see reults:
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Dim x, lr, c As Long
    
    lr = Cells(Rows.Count, 3).End(xlUp).Row
    c = 0
        For x = 11 To lr
            If Cells(x, 3).Value > Cells(4, 2).Value Then
            Cells(x, 4).Value = "NH"
            c = c + 1
            End If
        Next x
        MsgBox ("There are " & c & " NH employees as of " & Now())
    End Sub

  6. #6
    VBAX Expert mperrah's Avatar
    Joined
    Mar 2005
    Posts
    744
    Location

    updated file

    vba52574.xlsm
    just alter a few dates in your hired date column and double click a cell (anywhere)

  7. #7
    VBAX Expert mperrah's Avatar
    Joined
    Mar 2005
    Posts
    744
    Location
    This adds a clearcontents for the column so changes are easier to see as you test
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Dim x, lr, c As Long
    
    lr = Cells(Rows.Count, 3).End(xlUp).Row
    Range("D11:D" & lr).ClearContents
    c = 0
        For x = 11 To lr
            If Cells(x, 3).Value > Cells(4, 2).Value Then
            Cells(x, 4).Value = "NH"
            c = c + 1
            End If
        Next x
        MsgBox ("There are " & c & " NH employees as of " & Now())
    End Sub

  8. #8
    VBAX Expert mperrah's Avatar
    Joined
    Mar 2005
    Posts
    744
    Location
    be sure to double click a cell after you update values

  9. #9

  10. #10
    VBAX Regular
    Joined
    May 2015
    Posts
    27
    Location
    Thanks works great

  11. #11
    VBAX Expert mperrah's Avatar
    Joined
    Mar 2005
    Posts
    744
    Location
    glad to help,
    you can add a command button and paste the macro to that if you don't mind buttons.
    I thought the double click was less intrusive on your page layout.
    cheers
    -mark

Posting Permissions

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