Rule macro for the current date only

Hansulet

Board Regular
Joined
Jan 24, 2013
Messages
164
Office Version
  1. 2021
Platform
  1. Windows
I have the following macro:

Sub verificaCNP()


Dim lr As Long
lr = Range("A" & Rows.Count).End(xlUp).Row


For Each c In Range("G3:G" & lr).Cells
If c.Value <> "" Then
c.Activate
ActiveCell.Interior.ColorIndex = xlColorIndexNone
If Len(ActiveCell.Value) <> 13 Then
'MsgBox (ActiveCell.Value & ": CNP incorect - nu are 13 caractere")
ActiveCell.Interior.ColorIndex = 3
ActiveCell.Activate
Exit Sub
Else
If Not VerificCnp(ActiveCell.Value) Then
'MsgBox (ActiveCell.Value & ": CNP incorect.")
ActiveCell.Interior.ColorIndex = 3
ActiveCell.Activate
Exit Sub
End If
End If
End If
Next c
End Sub


I want this macro to be modified in order to rule for the current date only (the date is mentioned in column B)
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hi,

Current Date is accessible via the Date function in VBA

Code:
Sub verificaCNP()

 Dim lr As Long
 lr = Range("A" & Rows.Count).End(xlUp).Row
 For Each c In Range("G3:G" & lr)
 
    If c.Value = "" Or Cells(c.Row, "B").Value <> Date Then GoTo Skip
    
    c.Interior.ColorIndex = xlColorIndexNone
    
    If Len(c.Value) <> 13 Then
        'MsgBox (ActiveCell.Value & ": CNP incorect - nu are 13 caractere")
        c.Interior.ColorIndex = 3
        c.Activate
        Exit Sub
    Else
        If Not VerificCnp(c.Value) Then
            'MsgBox (ActiveCell.Value & ": CNP incorect.")
            c.Interior.ColorIndex = 3
            c.Activate
            Exit Sub
        End If
    End If
 
Skip:
 
 Next c
 
End Sub

I also changed a few things to make the code clearer, for example removed ActiveCell.Activate which does Nothing. (Activating the activated cell ??)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,549
Members
449,089
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top