ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Relative cell references (https://www.excelbanter.com/excel-programming/391118-relative-cell-references.html)

JimC

Relative cell references
 
I recorded a macro to enter the current time using the "Now()" function and
then copy and paste as a value so that the value remains constant. Then I
want to point to another cell and repeate the process. However the following
macro only goes back to the original cell that was used when the macro is
first invoked. How do I set a "relative cell reference? I'm trying to
create a time card template for posting an employee's log-in time and log-out
time and then compute total hours worked.

My Macro:
'TimeInput Macro
'
ActiveCell.FormulaR1C1 = "=NOW()"
Range ("B5").Select I want this to be
relative to
where the
currently selected cell is
Selection.Copy
Selection.PasteSpecial Paste:=x1PaxteValues, Operation:=x1None, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
End Sub

Trevor Shuttleworth

Relative cell references
 
Sub test()
ActiveCell.Value = Evaluate("=Now()")
ActiveCell.NumberFormat = "m/d/yyyy h:mm"
End Sub

This puts the current date and time into the active cell and formats it.

Where do you want to go to relative to the active cell ?

ActiveCell.Offset(0,1).Select will move one column to the right.
ActiveCell.Offset(1,0).Select will move one row down.

Regards

Trevor


"JimC" wrote in message
...
I recorded a macro to enter the current time using the "Now()" function and
then copy and paste as a value so that the value remains constant. Then I
want to point to another cell and repeate the process. However the
following
macro only goes back to the original cell that was used when the macro is
first invoked. How do I set a "relative cell reference? I'm trying to
create a time card template for posting an employee's log-in time and
log-out
time and then compute total hours worked.

My Macro:
'TimeInput Macro
'
ActiveCell.FormulaR1C1 = "=NOW()"
Range ("B5").Select I want this to be
relative to
where the
currently selected cell is
Selection.Copy
Selection.PasteSpecial Paste:=x1PaxteValues, Operation:=x1None, SkipBlanks
_
:=False, Transpose:=False
Application.CutCopyMode = False
End Sub




PCLIVE

Relative cell references
 
Your code is a bit overkill.

Sub MyMacro()
ActiveCell.Value = Now()
End Sub

Try this and then what do you want to do next?

Regards,
Paul


"JimC" wrote in message
...
I recorded a macro to enter the current time using the "Now()" function and
then copy and paste as a value so that the value remains constant. Then I
want to point to another cell and repeate the process. However the
following
macro only goes back to the original cell that was used when the macro is
first invoked. How do I set a "relative cell reference? I'm trying to
create a time card template for posting an employee's log-in time and
log-out
time and then compute total hours worked.

My Macro:
'TimeInput Macro
'
ActiveCell.FormulaR1C1 = "=NOW()"
Range ("B5").Select I want this to be
relative to
where the
currently selected cell is
Selection.Copy
Selection.PasteSpecial Paste:=x1PaxteValues, Operation:=x1None, SkipBlanks
_
:=False, Transpose:=False
Application.CutCopyMode = False
End Sub





All times are GMT +1. The time now is 11:47 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com