VBA code

Jagat Pavasia

Board Regular
Joined
Mar 9, 2015
Messages
244
Office Version
  1. 2019
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
 

Some videos you may like

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,479
Office Version
  1. 365
Platform
  1. Windows
Date is just that a date, rather than date & time, you need to use Now instead.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,479
Office Version
  1. 365
Platform
  1. Windows
In place of Date on this line
VBA Code:
If target.Value = "**" Then target.Value = Format(Date, "dd/mm/yyyy, hh:mm AM/PM")
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,479
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,466
Messages
5,624,908
Members
416,064
Latest member
PaulBr2

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
Top