In vba Return value of sheet 3 to sheet 1 if sheet 2 value is same to sheet 3 through array

Khan kashaf

New Member
Joined
May 11, 2021
Messages
14
Office Version
  1. 2019
  2. 2016
  3. 2010
Platform
  1. Windows
  2. MacOS
  3. Mobile
  4. Web
In VBA I have 3 sheets (output, source,city) city sheet contains 2 column city id and city name .. and my source sheet have random city id .then I have to print city name of those source id in output sheet through array

Sub fetch()
Dim arr()
Dim arr2()
last = Worksheets("source").Range("A1").End(xlDown).Row
arr = Range("A1:D" & last)
ActiveWorkbook.Sheets("Source").Select
Range("A1:D" & last).Value = arr


For i = LBound(arr, 1) To UBound(arr, 1)
Count = Count + 1
ReDim Preserve arr2(1 To last, 1 To 3)
arr2(Count, 1) = Trim(arr(i, 1))
arr2(Count, 2) = Trim(arr(i, 2))
arr2(Count, 3) = Trim(arr(i, 3))


ActiveWorkbook.Sheets("Output").Select
Sheets("Output").Columns("A:C").AutoFit
Range("A1:C" & Count).Value = arr2
Next


lastrow = Worksheets("City").Range("A1").End(xlDown).Row
arr3 = Range("A1:B" & last)


Here I have created array of sheet city and source sheet.. pls guide me
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
14,792
Office Version
  1. 2010
Platform
  1. Windows
In VBA I have 3 sheets (output, source,city) city sheet contains 2 column city id and city name .. and my source sheet have random city id .then I have to print city name of those source id in output sheet through array

Your description is very clear to me.
But what you have in your macro I don't understand.
Let's forget your code for a moment.

You could give an example of what you have in your source and city sheets. And the result you want in the output sheet.
Use the XL2BB tool minisheet to put the examples.
 

Khan kashaf

New Member
Joined
May 11, 2021
Messages
14
Office Version
  1. 2019
  2. 2016
  3. 2010
Platform
  1. Windows
  2. MacOS
  3. Mobile
  4. Web
Your description is very clear to me.
But what you have in your macro I don't understand.
Let's forget your code for a moment.

You could give an example of what you have in your source and city sheets. And the result you want in the output sheet.
Use the XL2BB tool minisheet to put the examples.
Thank you for the reply.. I have solved it
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,124
Messages
5,835,544
Members
430,366
Latest member
glastonbury

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