Formula - Macro

O

orquidea

Hi

How do I have to code the below procedure in a macro properly?

ATLN40 = "=Sum(B2:B4)"

I want to diplay the result in other cell. I have the following code:
Range("A1").Value= ATLN40 & " - 20's"
What I am getting now in Range A1 is =Sum(B2:B4) - 20's , not the
result of the sum.

Could anyone help me please?

Thanks,
Orquidea
 
C

CLR

Try this.........

Range("A1").Value = "=concatenate(SUM(B2:B4) & "" - 20 's"")"

Vaya con Dios,
Chuck, CABGx3
 
O

orquidea

Thanks for your answer.

I still need the variable ATLN40 = (the total of the sum) bacause I will
use the result of this variable for other calculation, so I will need to
refer to ATLN40.

Usted tambien vaya con Dios
 
C

CLR

If you don't get anything any better, this will work for a small range...

atln40 = Range("b2").Value + Range("b3").Value + Range("b4").Value

or you can compute the sum on the sheet in a helper cell and then refer to
that cell for the total

Vaya con Dios,
Chuck, CABGx3
 
D

Dave Peterson

Maybe...

Dim ATLN40 as double
ATLN40 = application.sum(worksheets("somesheetname").range("b2:b4"))

worksheets("somesheetname").range("a1").value = ATLN40 & " - 20's"
or
worksheets("somesheetname").range("a1").value _
= format(ATLN40, "0.000") & " - 20's"

=======
Or maybe if you want A1 to be a formula:

with worksheets("somesheetname")
.Range("a1").formula = "=SUM(B2:B4)&"" - 20's"""
end with

or maybe...

.Range("a1").formula = "=text(SUM(B2:B4),""0.000"")&"" - 20's"""

Depending on how you want it formatted.
 
C

CLR

Some lines from Dave's suggestions, and one from your original, seems to get
it....

Sub ConcatRangeSum()
Dim ATLN40 As Double
ATLN40 = Application.Sum(Worksheets("Sheet1").Range("b2:b4").Value)
'MsgBox ATLN40
Range("a1").Value = ATLN40 & " - 20 's"
End Sub

Vaya con Dios,
Chuck, CABGx3
 
O

orquidea

Thanks Dave for your help

Dave Peterson said:
Maybe...

Dim ATLN40 as double
ATLN40 = application.sum(worksheets("somesheetname").range("b2:b4"))

worksheets("somesheetname").range("a1").value = ATLN40 & " - 20's"
or
worksheets("somesheetname").range("a1").value _
= format(ATLN40, "0.000") & " - 20's"

=======
Or maybe if you want A1 to be a formula:

with worksheets("somesheetname")
.Range("a1").formula = "=SUM(B2:B4)&"" - 20's"""
end with

or maybe...

.Range("a1").formula = "=text(SUM(B2:B4),""0.000"")&"" - 20's"""

Depending on how you want it formatted.
 
O

orquidea

Thanks for your help

CLR said:
If you don't get anything any better, this will work for a small range...

atln40 = Range("b2").Value + Range("b3").Value + Range("b4").Value

or you can compute the sum on the sheet in a helper cell and then refer to
that cell for the total

Vaya con Dios,
Chuck, CABGx3
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top