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

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
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.
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,249
Members
452,623
Latest member
Techenthusiast

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