vba code help need

showarv2020

New Member
Joined
Nov 7, 2022
Messages
3
Office Version
  1. 2019
Platform
  1. Windows
Option Explicit

Sub Update_Current_Time()

Dim sh As Worksheet
Set sh = ActiveSheet

'''' Validations''''''''''
Dim rng As Range
Set rng = Selection

If Application.WorksheetFunction.CountBlank(rng) <> 1 Then
MsgBox "Incorrect range selection", vbCritical
Exit Sub
End If

If rng.Row < 5 Or rng.Row > 35 Then
MsgBox "Incorrect range selection", vbCritical
Exit Sub
End If

If rng.Column < 2 Or rng.Column > 30 Then
MsgBox "Incorrect range selection", vbCritical
Exit Sub
End If
If sh.Cells(rng.Row, 1).Value <> Int(Now) Then
MsgBox "You can update the time for today only", vbCritical
Exit Sub

End If

'''''''''''''''''''''

sh.Unprotect "1234"
rng.Value = Now
sh.Protect "1234"

End Sub



Sub Clear_sheet()

Dim sh As Worksheet
Set sh = ActiveSheet

sh.Unprotect "1234"
sh.Range("B5:G35").ClearContents
sh.Protect "1234"

End Sub
the underline VBA code are not working when i put my date in horizontally
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
What do you mean "not working"? What do you expect to happen, and what happens instead?

What do you mean by "put my date in horizontally"? You've just shown a bunch of code with no explanation of what it's supposed to do or what you are doing on the worksheet
 
Upvote 0
Actually i am writing a script to create automated time, for example: selecting any cell then when i click on update button in workbook the selected cell show current time. The bold line are written to match date in vertically putted in 1st column which allow me to capture time as previous in horizon. I want to do it vertically
 
Upvote 0
Here is the image where date are putted vertically but i want to put them horizontally in the top, what will be the code??
 

Attachments

  • image_a915cf6e-0254-471f-8ad4-e118f6e8779220221112_195647.jpg
    image_a915cf6e-0254-471f-8ad4-e118f6e8779220221112_195647.jpg
    133.9 KB · Views: 10
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,256
Members
448,557
Latest member
richa mishra

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