Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Inserting a Static Date and Time thru a Macro

Hi!

I have to insert a Static Date and Time in a Cell thru a Macro.

I know the key strokes for this function.

Current date Select a cell and press CTRL+;
Current time Select a cell and press CTRL+SHIFT+;

But I need to accomplish this in a Macro. Could anyone help me with
this?

When I tried to record a macro to capture these key strokes it didn't
work.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 142
Default Inserting a Static Date and Time thru a Macro

That's because the macro recorder won't pickup the control button...
Try this:

Sub EnterDate()
Dim thisdate As String
thisdate = Date$
Sheets(Sheet1).Range("B4").Value = thisdate
' or you could use the sheets vba name
' Sheet1.Range("B4").Value = thisdate

End Sub

Replace the sheet and range with your own and run the macro

Rob


wrote:
Hi!

I have to insert a Static Date and Time in a Cell thru a Macro.

I know the key strokes for this function.

Current date Select a cell and press CTRL+;
Current time Select a cell and press CTRL+SHIFT+;

But I need to accomplish this in a Macro. Could anyone help me with
this?

When I tried to record a macro to capture these key strokes it didn't
work.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 142
Default Inserting a Static Date and Time thru a Macro

Sorry, you wanted both time and date:

Sub EnterDate()
Dim thisdate As String, thistime As String
thisdate = Date$
thistime = Time$
Sheets("Sheet1").Range("B4").Value = thisdate
' or you could use the sheets vba name
'Sheet1.Range("B4").Value = thisdate
Sheets("Sheet1").Range("B5").Value = thistime
End Sub

Also on the previous, I forgot the "" around the sheet name
Sheets(Sheet1) should be Sheet("Sheet1")

Rob



okrob wrote:
That's because the macro recorder won't pickup the control button...
Try this:

Sub EnterDate()
Dim thisdate As String
thisdate = Date$
Sheets(Sheet1).Range("B4").Value = thisdate
' or you could use the sheets vba name
' Sheet1.Range("B4").Value = thisdate

End Sub

Replace the sheet and range with your own and run the macro

Rob


wrote:
Hi!

I have to insert a Static Date and Time in a Cell thru a Macro.

I know the key strokes for this function.

Current date Select a cell and press CTRL+;
Current time Select a cell and press CTRL+SHIFT+;

But I need to accomplish this in a Macro. Could anyone help me with
this?

When I tried to record a macro to capture these key strokes it didn't
work.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Inserting a Static Date and Time thru a Macro

Great. Worked like a charm. Thanks a lot.

okrob wrote:
Sorry, you wanted both time and date:

Sub EnterDate()
Dim thisdate As String, thistime As String
thisdate = Date$
thistime = Time$
Sheets("Sheet1").Range("B4").Value = thisdate
' or you could use the sheets vba name
'Sheet1.Range("B4").Value = thisdate
Sheets("Sheet1").Range("B5").Value = thistime
End Sub

Also on the previous, I forgot the "" around the sheet name
Sheets(Sheet1) should be Sheet("Sheet1")

Rob



okrob wrote:
That's because the macro recorder won't pickup the control button...
Try this:

Sub EnterDate()
Dim thisdate As String
thisdate = Date$
Sheets(Sheet1).Range("B4").Value = thisdate
' or you could use the sheets vba name
' Sheet1.Range("B4").Value = thisdate

End Sub

Replace the sheet and range with your own and run the macro

Rob


wrote:
Hi!

I have to insert a Static Date and Time in a Cell thru a Macro.

I know the key strokes for this function.

Current date Select a cell and press CTRL+;
Current time Select a cell and press CTRL+SHIFT+;

But I need to accomplish this in a Macro. Could anyone help me with
this?

When I tried to record a macro to capture these key strokes it didn't
work.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
embedded static time & date james Excel Worksheet Functions 3 May 17th 09 05:40 PM
Inserting static time that doesn't update kefee85 Excel Discussion (Misc queries) 1 February 13th 09 08:15 PM
static date and time Wanna Learn Excel Discussion (Misc queries) 2 January 29th 09 05:05 PM
Inserting a static date into a function FIF780 Excel Worksheet Functions 5 February 1st 07 10:39 PM
how can i set a static date and time in excel ucastores Excel Worksheet Functions 2 June 3rd 06 01:38 AM


All times are GMT +1. The time now is 06:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"