I have workbook that has a tab for each week in a month. I have used a VBA userform with a multiselect listbox to allow the user to select multiple worksheets to roll-up into a summary worksheet. My problem is writting the sum formula to accept the listbox's array.
Here is my code. I have used the loop portion in other projects to copy and move worksheets to new workbooks and it works fine.
Private Sub CommandButton1_Click()
Worksheets(Worksheets.Count).Copy after:=Worksheets(Worksheets.Count)
ActiveSheet.Name = TextBox1.Text
Range("B2:H26,K2:O26,B32:k55").Select
Selection.ClearContents
Range("A1").Select
Selection.FormulaR1C1 = TextBox1.Text
Dim iloop As Integer
Dim arr()
Dim cntr As Variant
cntr = 0
For iloop = 1 To ListBox1.ListCount
If ListBox1.Selected(iloop - 1) = True Then
ListBox1.AddItem ListBox1.List(iloop - 1)
cntr = cntr + 1
ReDim Preserve arr(cntr)
arr(cntr) = ListBox1.List(iloop - 1)
End If
Next
Range("B2:H26,K2:O26,B32:k55").Select
Selection.FormulaR1C1 = "=sum(worksheets(arr(cntr))!RC)" 'this is where I am having my summing multiple sheets issues.
Unload UserForm1
End Sub
Here is my code. I have used the loop portion in other projects to copy and move worksheets to new workbooks and it works fine.
Private Sub CommandButton1_Click()
Worksheets(Worksheets.Count).Copy after:=Worksheets(Worksheets.Count)
ActiveSheet.Name = TextBox1.Text
Range("B2:H26,K2:O26,B32:k55").Select
Selection.ClearContents
Range("A1").Select
Selection.FormulaR1C1 = TextBox1.Text
Dim iloop As Integer
Dim arr()
Dim cntr As Variant
cntr = 0
For iloop = 1 To ListBox1.ListCount
If ListBox1.Selected(iloop - 1) = True Then
ListBox1.AddItem ListBox1.List(iloop - 1)
cntr = cntr + 1
ReDim Preserve arr(cntr)
arr(cntr) = ListBox1.List(iloop - 1)
End If
Next
Range("B2:H26,K2:O26,B32:k55").Select
Selection.FormulaR1C1 = "=sum(worksheets(arr(cntr))!RC)" 'this is where I am having my summing multiple sheets issues.
Unload UserForm1
End Sub