H
Howard
Earlier today Claus offered me a simpler version of copy array to an array code.
Here I have embellished it to copy from one array to four arrays.
As below, is this in line with best practices? It works fine as is, however on the fourth array I thought I could use... myArr5 = Array("L5:L12") but it errors out. Seems to want each cell listed in the array. I have seen an example in a google search where...
myArr5 = Array("L5:L12").Select
Selection = myArray
Or something similar.
The code is in a standard Module 1 of the workbook.
Your thoughts please.
Thanks.
Howard
Option Explicit
Sub Fill_Array_Add_To_Sheet()
Dim myarray(8) As Variant
Dim myArr2 As Variant
Dim myArr3 As Variant
Dim myArr4 As Variant
Dim myArr5 As Variant
Dim i As Integer
Sheets("Sheet1").Activate
myarray(0) = Range("F13")
myarray(1) = Range("F16")
myarray(2) = Range("F19")
myarray(3) = Range("I13")
myarray(4) = Range("I16")
myarray(5) = Range("I19")
myarray(6) = Range("L13")
myarray(7) = Range("K17")
Sheets("Sheet2").Activate
myArr2 = Array("F3", "C3", "D3", "I3", "J3", "M3", "O3", "P3")
myArr3 = Array("A3", "B5", "C7", "D9", "E11", "F13", "G15", "H17")
myArr4 = Array("A20", "B20", "C20", "D20", "E20", "F20", "G20", "H20")
myArr5 = Array("L5", "L6", "L7", "L8", "L9", "L10", "L11", "L12")
For i = LBound(myArr2) To UBound(myArr2)
Range(myArr2(i)) = myarray(i)
Range(myArr3(i)) = myarray(i)
Range(myArr4(i)) = myarray(i)
Range(myArr5(i)) = myarray(i)
Next
End Sub
Here I have embellished it to copy from one array to four arrays.
As below, is this in line with best practices? It works fine as is, however on the fourth array I thought I could use... myArr5 = Array("L5:L12") but it errors out. Seems to want each cell listed in the array. I have seen an example in a google search where...
myArr5 = Array("L5:L12").Select
Selection = myArray
Or something similar.
The code is in a standard Module 1 of the workbook.
Your thoughts please.
Thanks.
Howard
Option Explicit
Sub Fill_Array_Add_To_Sheet()
Dim myarray(8) As Variant
Dim myArr2 As Variant
Dim myArr3 As Variant
Dim myArr4 As Variant
Dim myArr5 As Variant
Dim i As Integer
Sheets("Sheet1").Activate
myarray(0) = Range("F13")
myarray(1) = Range("F16")
myarray(2) = Range("F19")
myarray(3) = Range("I13")
myarray(4) = Range("I16")
myarray(5) = Range("I19")
myarray(6) = Range("L13")
myarray(7) = Range("K17")
Sheets("Sheet2").Activate
myArr2 = Array("F3", "C3", "D3", "I3", "J3", "M3", "O3", "P3")
myArr3 = Array("A3", "B5", "C7", "D9", "E11", "F13", "G15", "H17")
myArr4 = Array("A20", "B20", "C20", "D20", "E20", "F20", "G20", "H20")
myArr5 = Array("L5", "L6", "L7", "L8", "L9", "L10", "L11", "L12")
For i = LBound(myArr2) To UBound(myArr2)
Range(myArr2(i)) = myarray(i)
Range(myArr3(i)) = myarray(i)
Range(myArr4(i)) = myarray(i)
Range(myArr5(i)) = myarray(i)
Next
End Sub