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."
 

Some videos you may like

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Watch MrExcel Video

Forum statistics

Threads
1,127,557
Messages
5,625,500
Members
416,113
Latest member
Zulwaqar88

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
Top