My array

Incogn1to

New Member
Joined
Aug 24, 2020
Messages
4
Office Version
  1. 365
Platform
  1. Windows
I have built an function that (should) copy relevant cells from one worksheet to another worksheet. However the code does not function properly and if I move to the loop it only return blank cells. What goes wrong?
Hope you can help!

VBA Code:
Sub nieuw2()

Dim MyArray As Variant
Dim wb As Worksheet

Dim i As Long
Dim c As Long
Dim FoundCell As Range

Set wb = ThisWorkbook.Sheets("Import")
Cells.ClearOutline


ReDim MyArray(1 To i, 1 To c)
             '


For c = 1 To wb.Columns.Count
        c = c + 1
    For i = 1 To wb.Rows.Count
       ' If wb.DataBodyRange(a, b).Value > 0 Then
            'LookupValue = bron1.DataBodyRange(a, 2).Value
            'Set FoundCell = bron2.DataBodyRange.Columns(4).Find(LookupValue, LookAt:=xlWhole)
           ' Rijnummer = FoundCell.Row - 1
            i = i + 1
            MyArray(i, 1) = wb.Cells(1, 3).Value
            MyArray(i, 2) = wb.Cells(1, 4).Value
            MyArray(i, 3) = wb.Cells(1, 7).Value
            MyArray(i, 4) = wb.Cells(i, 10).Value
            MyArray(i, 7) = "text"
            MyArray(i, 10) = "text"
       ' End If
    Next i
    
Next c

ThisWorkbook.Sheets("targetfile").Cells(1, 2) = MyArray
MsgBox "Export done."
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Forum statistics

Threads
1,214,567
Messages
6,120,268
Members
448,953
Latest member
Dutchie_1

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top