Мне нужно скопировать данные, но поскольку объем данных, требующих копирования, будет довольно большим и заполнен вручную, я хотел бы сделать это с помощью макроса.Массив для копирования
Я не могу понять, как работают массивы.
Это дает мне нужное количество копий, но только из последней ячейки, которую мне нужно скопировать.
Sub copyer()
Dim fromH As Integer 'fromheight
Dim fromW As Integer 'fromwidth
Dim toH As Integer 'to height
Dim toW As Integer 'to width
Dim counter As Integer
counter = Worksheets("blad1").Range("D3").Value 'amount of filled-in data lines to copy
Dim Times As Integer 'number of times to run the loop, depending on the filled in data
Times = counter + 1
Dim tostart As Integer 'location where to start placing the data
'depending on how much data is already present
Dim toend As Integer 'location up to where to place
tostart = Sheets("blad2").Range("L1").Value + 1 '(+2 if theres a header)
toend = tostart + counter
Dim Copy As Integer
For Copy = 1 To Times
For toH = tostart To toend
For toW = 1 To 2
For fromH = 12 To 22 Step 2
For fromW = 1 To 26 Step 25
Sheets("blad2").Cells(toH, toW).Value = _
Sheets("blad1").Cells(fromH, fromW).Value
Next fromW
Next fromH
Next toW
Next toH
Next Copy
'this macro needs to copy the data
'from blad1
'from height 12 to 22 (steps of 2)(10 times)
'from width 1 and 26 (not the cells inbetween)
'to blad2
'to height depending on the data present (dim tostart)'till height needed (steps of 1)
'to width 1 and 2
'blad1, D3 holds the input-datacounter
'blad2, L1 holds the output-datacounter
End Sub
Это не совсем понятно, что вы пытаетесь делать. Сложно, что у вас будет 5x вложенный цикл 'For'. Вы перешли через код, используя F8, чтобы вручную пройти процесс и посмотреть, где он отличается от ваших ожиданий? Если нет, это должен быть ваш первый шаг в отладке. –
мой ответ [здесь] (http://stackoverflow.com/questions/14035772/how-to-assign-an-excel-range-to-a-2d-array/14060707#14060707) должен помочь вам в копировании диапазона от и до массива. – SeanC