Khan kashaf
New Member
- Joined
- May 11, 2021
- Messages
- 14
- Office Version
- 2019
- 2016
- 2010
- Platform
- Windows
- MacOS
- Mobile
- 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
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