Array Help - Populating matching data from 1 to another

JumboCactuar

Well-known Member
Joined
Nov 16, 2016
Messages
785
Office Version
  1. 365
Platform
  1. Windows
Hi,

Best to describe what im trying to figure out is (vlookup from 1 array to another)

Screenshot of Worksheet - The yellow is what im trying to populate within array



Here is my code to build the 2 arrays, and the total is working

VBA Code:
Sub ArrayTest()
Dim DataArray As Variant
Dim NewArray As Variant

DataArray = Range("K2:P228")

LR = Sheet6.Range("A10000").End(xlUp).Row

NewArray = Range("A2:G" & LR)

For i = 1 To UBound(NewArray, 1)

    'How to get B,C,D,E,F values from DataArray ?

    'Get Totals
    NewArray(i, 7) = NewArray(i, 2) + NewArray(i, 3) + NewArray(i, 4) + NewArray(i, 5) + NewArray(i, 6)

Next i

End Sub


appreciate any help
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
edit:
figured 1 way but maybe something that works faster?

VBA Code:
NewArray(i, 2) = WorksheetFunction.VLookup(NewArray(i, 1), DataArray, 2, False)
NewArray(i, 3) = WorksheetFunction.VLookup(NewArray(i, 1), DataArray, 3, False)
NewArray(i, 4) = WorksheetFunction.VLookup(NewArray(i, 1), DataArray, 4, False)
NewArray(i, 5) = WorksheetFunction.VLookup(NewArray(i, 1), DataArray, 5, False)
NewArray(i, 6) = WorksheetFunction.VLookup(NewArray(i, 1), DataArray, 6, False)
 
Upvote 0
VBA Code:
NewArray(i, 2) = Application.VLookup(NewArray(i, 1), DataArray, 2, False)
If IsError(NewArray(i, 2)) then NewArray(i, 2) = 0

Application.VLookup instead so you can handle errors if not found
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,871
Members
449,054
Latest member
juliecooper255

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