Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2
Default Quote marks in Formulas passed from VB Script in Excel

Interesting one. I have a calculation subroutine that goes row by row to see
if there are any matching records that have three same fields of information
in them. If they do then it tries to replace the value of the last record
with a formula that will calcuate a difference between two times.
Unfortunately I don't know how to pass the " marks in the
TEXT(CELL1-CELL2,"h:mm") formula. Or I could try calculating the time
difference in the routine and just passing the value, but I don't know how to
use an excel function in a VB subroutine (the problem is that the values are
TIMES in the cells to be calculated). It's Friday, I'm toast.

Sub CalculateTurnover()
For n = 2 To 5392 (my row range)
Rem - see if date, employee and room match (columns 3,4,10) with the
following row
If (Cells(n, 3) = Cells(n + 1, 3)) And (Cells(n, 4) = Cells(n + 1, 4)) And
(Cells(n, 10) = Cells(n + 1, 10)) Then
Rem - if so put formula to calculate time difference and store it into
column 12
Cells(n + 1, 12).Formula = "=TEXT(" & Cells(n, 9).Value & "-" &
Cells(n + 1, 5).Value & ',"h:mm")'
End If
Next n
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default Quote marks in Formulas passed from VB Script in Excel

Double them up.

But since you're populating the cell with a formula, I would think that your
formula should be a formula that adjusts when the cell precedents change--maybe:

Option Explicit
Sub CalculateTurnover()
Dim n As Long
For n = 2 To 5392 '(my row range)
'see if date, employee and room match (columns 3,4,10)
'with the following Row
If (Cells(n, 3).Value = Cells(n + 1, 3).Value) _
And (Cells(n, 4).Value = Cells(n + 1, 4).Value) _
And (Cells(n, 10).Value = Cells(n + 1, 10).Value) Then
'if so put formula to calculate time difference
'and store it into Column 12
Cells(n + 1, 12).Formula _
= "=TEXT(" & Cells(n, 9).Address & "-" _
& Cells(n + 1, 5).Address & ",""h:mm"")"
End If
Next n
End Sub


Graysailor wrote:

Interesting one. I have a calculation subroutine that goes row by row to see
if there are any matching records that have three same fields of information
in them. If they do then it tries to replace the value of the last record
with a formula that will calcuate a difference between two times.
Unfortunately I don't know how to pass the " marks in the
TEXT(CELL1-CELL2,"h:mm") formula. Or I could try calculating the time
difference in the routine and just passing the value, but I don't know how to
use an excel function in a VB subroutine (the problem is that the values are
TIMES in the cells to be calculated). It's Friday, I'm toast.

Sub CalculateTurnover()
For n = 2 To 5392 (my row range)
Rem - see if date, employee and room match (columns 3,4,10) with the
following row
If (Cells(n, 3) = Cells(n + 1, 3)) And (Cells(n, 4) = Cells(n + 1, 4)) And
(Cells(n, 10) = Cells(n + 1, 10)) Then
Rem - if so put formula to calculate time difference and store it into
column 12
Cells(n + 1, 12).Formula = "=TEXT(" & Cells(n, 9).Value & "-" &
Cells(n + 1, 5).Value & ',"h:mm")'
End If
Next n
End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2
Default Quote marks in Formulas passed from VB Script in Excel

Just in case someone needs to know how - I figured out how to do it:
Sub CalculateTurnover()

For n = 2 To 5392
If (Cells(n, 1) = Cells(n + 1, 1)) And (Cells(n, 2) = Cells(n + 1, 2))
And (Cells(n, 3) = Cells(n + 1, 3)) Then
Rem MsgBox ("Duplicate Date & Room & Employee in " & Cells(n + 1,
1).Address & Cells(n + 1, 2).Address & Cells(n + 1, 3).Address)
Cells(n + 1, 6).Formula = "=TEXT(" & Cells(n, 4).Value & "-" & Cells(n
+ 1, 5).Value & "," & """h:mm""" & ")"

End If
Next n
End Sub


"Graysailor" wrote:

Interesting one. I have a calculation subroutine that goes row by row to see
if there are any matching records that have three same fields of information
in them. If they do then it tries to replace the value of the last record
with a formula that will calcuate a difference between two times.
Unfortunately I don't know how to pass the " marks in the
TEXT(CELL1-CELL2,"h:mm") formula. Or I could try calculating the time
difference in the routine and just passing the value, but I don't know how to
use an excel function in a VB subroutine (the problem is that the values are
TIMES in the cells to be calculated). It's Friday, I'm toast.

Sub CalculateTurnover()
For n = 2 To 5392 (my row range)
Rem - see if date, employee and room match (columns 3,4,10) with the
following row
If (Cells(n, 3) = Cells(n + 1, 3)) And (Cells(n, 4) = Cells(n + 1, 4)) And
(Cells(n, 10) = Cells(n + 1, 10)) Then
Rem - if so put formula to calculate time difference and store it into
column 12
Cells(n + 1, 12).Formula = "=TEXT(" & Cells(n, 9).Value & "-" &
Cells(n + 1, 5).Value & ',"h:mm")'
End If
Next n
End Sub

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
How do you print showing formulas in Excel 2000? Kim Excel Discussion (Misc queries) 3 June 16th 08 09:56 PM
Please help with Statistics Formulas in Excel Fonz Excel Discussion (Misc queries) 10 April 9th 06 03:22 PM
VB script in Excel object in Powerpoint (Urgent) epak Excel Discussion (Misc queries) 1 March 24th 06 05:04 PM
Putting Excel formatting and/or formulas into CSV file Frank D. Nicodem, Jr. Excel Discussion (Misc queries) 1 July 11th 05 10:18 PM
I want Excel to allow cells with formulas and unrelated text blueboy Excel Discussion (Misc queries) 9 March 4th 05 12:22 AM


All times are GMT +1. The time now is 07:36 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"