VBA code

Jagat Pavasia

Active Member
Joined
Mar 9, 2015
Messages
359
Office Version
  1. 2021
Platform
  1. Windows
i have VBA code, when i enter "**" i want currant date and time.
but only currant date is showing, the time is always showing 12:00 AM

please help with edit below VBA code

VBA Code:
Sub Macro2(target As Range)
Dim Rng As Range

  If target.Count > 1 Then Exit Sub
  Application.EnableEvents = False
  ActiveSheet.Unprotect
  Set Rng = Range("b:b,g:g,j:j,M:M")
  If Not Intersect(target, Rng) Is Nothing Then
    If target.Value = "**" Then target.Value = Format(Date, "dd/mm/yyyy, hh:mm AM/PM")
  End If

  If Not Intersect(target, Range("B4:R4")) Is Nothing Then
      If target.Value = "" Then
          ActiveSheet.Range("B6:R6").AutoFilter Field:=target.Column
      Else
          ActiveSheet.Range("B6:R6").AutoFilter Field:=target.Column, Operator:=xlFilterValues, Criteria1:=CStr(target.Value)
      End If
  End If
  ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
        False, AllowFormattingCells:=True, AllowFiltering:=True
  Application.EnableEvents = True
End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Date is just that a date, rather than date & time, you need to use Now instead.
 
Upvote 0
In place of Date on this line
VBA Code:
If target.Value = "**" Then target.Value = Format(Date, "dd/mm/yyyy, hh:mm AM/PM")
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,267
Members
449,075
Latest member
staticfluids

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