I am trying to create an array, store values in the array and then write the values of the array to a spreadsheet in VBA. This codes takes 1+ hour to run on my computer and I think that an array could really speed up the code.
However, I need help with creating the array, populating the array from the comboboxes and finally write the values of the array to the worksheet.
- Create an n-dimensional array
- Fill the n-dimensional array with the values of the ComboBoxes.
- Iterate through all ComboBoxes.
- Store values in the array
Write values from the array to the spreadsheet
Sub WantToUseArray()
Dim k As Integer Dim l As Integer Sheets("Test").ComboBox1.ListIndex = 0 For l = 0 To 25 Sheets("Test").ComboBox3.ListIndex = l Sheets("Test").ComboBox2.ListIndex = 0 For n = 0 To 25 Sheets("Test").ComboBox4.ListIndex = n Sheets("Points").Select Dim LR As Long LR = Cells(Rows.Count, 1).End(xlUp).Row + 1 Cells(LR, "A").Value = Sheets("Test").Range("G5").Value Cells(LR, "B").Value = Sheets("Test").Range("G6").Value Cells(LR, "C").Value = Sheets("Test").Range("O5").Value Cells(LR, "D").Value = Sheets("Test").Range("O6").Value Cells(LR, "E").Value = Sheets("Test").Range("X5").Value Cells(LR, "F").Value = Sheets("Test").Range("X6").Value Cells(LR, "G").Value = Sheets("Test").Range("G6").Value + Sheets("Test").Range("X6").Value Cells(LR, "H").Value = Sheets("Test").Range("X6").Value + Sheets("Test").Range("G6").Value Cells(LR, "I").Value = Sheets("Test").Range("K40").Value Cells(LR, "J").Value = Sheets("Test").Range("K41").Value Cells(LR, "K").Value = Sheets("Test").Range("K51").Value Cells(LR, "L").Value = Sheets("Test").Range("K52").Value Next Next End Sub
