VBA Sum and Value in a UserForm Label

skeut -  
 skeut -
Hello everyone!

I need to add a feature to a small Excel application;
it involves summing a column and displaying the result in a label of the userform. I've looked for a solution but I'm struggling, can someone please help me?

So, it’s about
1- summing
2- retrieving the sum in the label

Thank you in advance for your help.
Have a great day everyone.

5 answers

skeut
 
Thank you for your response Armojax,

it indeed works as you suggested; the problem is that the total does not appear on the sheet (because rows are regularly added/removed), I would like to sum just before displaying the result in the label.

Is it possible?

See you around. skeut
2
Armojax
 
Hello skeut,

If your total is in line 6, column 1 of the sheet Feuil1:

Label.Caption = Sheets("Feuil1").Cells(6, 1).Value
1
skeut
 
- I have a single userform for multiple sheets.
- The range to sum is always the range G2:G10000.
- In principle, there are no blank rows between the different tuples.

Is it necessary to name the range, or can we identify the cells by G2:G10000?

I hope these clarifications answer your questions, and I thank you in advance for your valuable help.

See you later. Skeut
1
Armojax
 
Here I am again,

I had lunch and drank my coffee, I'm fine...

So, assuming your sheet is named "Feuille", and your label is named "Label", you can write:

Dim Plage As Range
Set Plage = Sheets("Feuille").Range("G2:G10000")
Label.Caption = Application.WorksheetFunction.Sum(Plage)

It works for me.
Hoping it will work well for you too

Armojax.
0
Armojax
 
OK. Just a small question before answering you: How can you identify the cells you want to sum?
Are they always in the same sheet? In the same column? How can the relevant range be recognized? Does the first cell always have the same address? Are there empty rows after the last row of the range to be summed? Etc.

Armojax.
0
skeut
 
Armojax,

this is a world-class response!!!

It works perfectly; I just replaced <<sheets>> with <<activesheet>>. So, it gives me the total in the sheet I’m on.

Thanks again and maybe see you next time.
Skeut</activesheet></sheets>
0