Thank you very much!
Beautiful, thank you!
What if I wanted to put the total for each row in column F instead of a lump sum? Would that be possible?
Here you go. The user would click on the column header instead of selecting the range.
Thanks again, Roy!
The purpose of the macro is to allow the user to select any number of columns and sum them up. Assuming that there will always be 3 columns for the user to select, and that the user selects 2 out of the three, what code would be equivalent to "still perform calculation even if not all three columns are selected"?
Right now, the output of "Totals" is blank if not all three columns are selected.
The indicies and header names of the columns I want to evaluate vary by sheet, so I had to resort to refedit to give the user the flexibility to select the correct columns.
Thanks, Roy. Unfortunately, I get Run-time error "424" - Object Required. It didn't like the if statements for some reason...
MODERATOR NOTICE: This topic has also been posted on other sites and may already have an answer elsewhere. Please take this into consideration when answering this question
How can I ignore a blank RefEdit when adding ranges? I have the following:Code
- Private Sub CommandButton1_Click()
- Dim lRow as Long
- lRow = Cells(Rows.Count, "A").End(xlUp).Row
- Column1= RefEdit1.Value
- Set Rng1= Range(Column1)
- Column2= RefEdit2.Value
- Set Rng2= Range(Column2) Column3= RefEdit3.Value
- Set Rng3= Range(Column3)
- Set Total= Range("F2:F" & lRow)
- For i = 1 To lRow - 1 Total(i, 1) = Rng1(i, 1) + Rng2(i, 1) + Rng3(i, 1)
- End Sub
This works perfectly if all RefEdits are populated, but nothing happens if one is missing. I can add an "On Error Resume Next", but that doesn't address the problem that no output is shown. How can I say "If Rng1, Rng2, or Rng3 are blank, exclude from calculation"?