Sum of 2 cells in VBA

Sirhill -  
Polux31 Posted messages 7219 Status Membre -
Hello,

I have a small issue because I want to add 2 cells from one sheet and put the result in a cell from another sheet. But the VBA formula I used does not work.
Could you help me solve this little problem, thank you in advance.
Here is my line of code:

Worksheets("DI").Range("Q" & MaxDI).Value = Application.WorksheetFunction.Sum(Sheets("Budget").Range("AV" & CptBudget), Sheets("Budget").Range("AT" & CptBudget))

Thank you for your help.
CR

2 réponses

Polux31 Posted messages 7219 Status Membre 1 204
 
Hello,

In principle:

Worksheets(2).Range("A1").Value = Worksheets(1).Range("A1").Value + Worksheets(1).Range("A2").Value

;o)
--
"What is well conceived is clearly stated, And the words to say it come easily."
Nicolas Boileau
1
Sirhill
 
Thank you for your response. I tried, but it doesn’t work. (But your formula is good)
I found the problem, it’s that the original cells are in text format (due to the conversion of a .csv file), so when I add them, it concatenates the two cells.

I’m now trying to find how to convert the format of the column from the .csv file to number format when I perform my extraction????

Here is the code I’m using..

'Allows converting the data copied from the CSV
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=True, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(Array(1, 1), Array(2, 1), Array(3, 1), TrailingMinusNumbers :=True


Thank you

CR
0
Polux31 Posted messages 7219 Status Membre 1 204
 
re

To convert:

Worksheets(2).Range("A1").Value = CDbl(Worksheets(1).Range("A1").Value) + CDbl(Worksheets(1).Range("A2").Value)

;o)

--
“What is well conceived is clearly expressed, And the words to say it come easily.”
Nicolas Boileau
1