PDA

View Full Version : [SOLVED] Combine two arguments into one.



PAB
01-24-2017, 09:46 AM
Good afternoon,

Both the below work on their own.
How can I combine them into one line please.
I have tried evaluate but without any success.


Range("B10").Value = _
Format(x, "###,###,###") & " ********* Generated In: " & _
Format(((Timer - Start) / 24 / 60 / 60), "hh:mm:ss") & " Seconds"
Range("M10").Value = "=If(SUM(C8:O8)-" & x & "=0,""Check: OK"",""Check: NOT OK"")"

By that I mean taking out the...


Range("M10").Value

...so it all goes in B10.

Thanks in advance.

Paul_Hossler
01-24-2017, 10:03 AM
Q1: you want to combine the Range("B10").Value = and the Range("M10").Value = into one statement? Why?

Q2: Shouldn't Range("M10").Value = be Range("M10").Formula?

PAB
01-24-2017, 10:21 AM
Sorry, I didn't explain that very well.

It should read something like this...

12 ********* Genereated In: 00:00:00 Seconds > Check: OK

...or...

12 ********* Genereated In: 00:00:00 Seconds > Check: NOT OK

Thanks in advance.

Paul_Hossler
01-24-2017, 11:57 AM
Sorry, but still not 100% clear to me

Maybe a user defined function would be a way to go





Option Explicit

Function test(X As Double, S As Double, R As Range) As String
Dim sOut As String

sOut = Format(X, "###,###,###") & " ********* Generated In: "
sOut = sOut & Format(((Timer - S) / 24 / 60 / 60), "hh:mm:ss") & " Seconds: "

'close enough to be equal
If Abs(X - Application.WorksheetFunction.Sum(R)) < 10 ^ 5 Then
sOut = sOut & "OK"
Else
sOut = sOut & "Not OK"
End If
test = sOut
End Function

PAB
01-24-2017, 12:11 PM
Thanks for the reply Paul it is appreciated.

I can go with that.
I was actually trying to achieve it using the Concatenate function but without any success.
I got close, but not close enough.
I really just wanted to add the...


"=If(SUM(C8:O8)-" & x & "=0,""Check: OK"",""Check: NOT OK"")"

...bit to the end of...


Range("B10").Value = _
Format(x, "###,###,###") & " ********* Genereated In: " & _
Format(((Timer - Start) / 24 / 60 / 60), "hh:mm:ss") & " Seconds"

Thanks again.

SamT
01-24-2017, 12:30 PM
Dim ck As String

If WorksheetFunction.Sum(Range("C8:O8")) = x then
ck = " > Check: OK"
Else
ck = " > Check: NOT OK"
End If

Range("B10").Value = _
Format(x, "###,###,###") & " ********* Generated In: " & _
(Timer - Start) / 24 / 60 / 60) & " Seconds" & ck

PAB
01-24-2017, 12:42 PM
Brilliant SamT, thanks very much.