Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set (15/1440) as a variable 1

Status
Not open for further replies.

WaterSprite

Technical User
Mar 23, 2004
69
0
0
US

Dim x As Date, xx As Integer, thisTime As Date,Date1 As Date
Dim y As Date, z As Integer, a As Integer, b As Integer, bb As Integer, aa As Integer
With Activesheet
Cells.Clear
aa = 10
bb = 9
b = 384
Date1 = Format$(Date, "dd-mmm-yyyy hh:mm")
Cells(9, 1).Value = Date1
thisTime = #12:15:00 AM#
xx = Minute(thisTime)
Cells(6, 1).Value = xx
ActiveWorkbook.Names.Add Name:=("PB9"), _
RefersToR1C1:="=" & "!R" & aa & "C1:R" & b & "C1"
Range("PB9").FormulaR1C1 = "=(R[-1]C1) + (15/1440)"
Range("PB9").NumberFormat = "dd-mmm-yyyy hh:mm"
End With

*********************************
This code, as you see it, works. What I want to do, and have spent almost two days trying to do,
is set the (15/1440) in this line [Range("PB9").FormulaR1C1 = "=(R[-1]C1) + (15/1440)"]
to a variable, thus the xx in the body of the code. But, nothing I do works.
 
Like this ?
Range("PB9").FormulaR1C1 = "=(R[-1]C1) + " & xx

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV, your solution worked perfectly. BTW, I think you gave me the named range code that I am using in this a couple of years ago. So, thanks for the named range code and for this new code.
After I saw yours, I realized I had sort of been all around what you did, just never thought of moving the last " back to the inside. Now I have to figure out how to get xx to equal 15 minutes. The way I have it written now. xx equals 15 days, so my date/time stamps are jumping 15 days at a time, not 15 minutes. But, again, thanks for the help. I can probably figure out the 15 minute thing myself.
 
I'd try this:
Range("PB9").FormulaR1C1 = "=(R[-1]C1) + " & (xx / (24 * 60))

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,
What finally worked, just now, was this:

[Cells(5,1).formulaR1C1 = "=Sum(15/1440)"]

[xx = Cells(5,1).value]

[ActiveWorkbook.Names.Add Name:=("PB9"), _
RefersToR1C1:="=" & "!R" & aa & "C1:R" & b & "C1"]

[Range("PB9").FormulaR1C1 = "=(R[-1]C1) + " & xx ]

[Range("PB9").NumberFormat = "dd-mmm-yyyy hh:mm" ]

The great thing about this is I can use Select Case to change the statement in Cells(5,1), which then changes the value in the variable xx from one minute increments to 15 minute increments to 1 hour increments.

Thanks again for your assistance and suggestions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top