![]() |
Iterate rows of spreadsheet(s}\Get values
I have two spreadsheets. The first one has a column with numbers in it.
The second one has a column with the same numbers and a description column as well. Each number can have more than one description. What I want to do do is iterate the rows in Sheet 1 and lookup the numbers in sheet 2. Then return all the descriptions to sheet 1 and put them in the cell next to the number. If there are multiple descriptions for a number we would like them separated by a comma. Is there a function for something like this? TIA |
Iterate rows of spreadsheet(s}\Get values
You can use the macro below.
Sub test() With Sheets("Sheet1") Sh1RowCount = 1 Do While .Range("A" & Sh1RowCount) < "" data = .Range("A" & Sh1RowCount) With Sheets("Sheet2") Sh2RowCount = 1 Description = "" Do While .Range("A" & Sh2RowCount) < "" If .Range("A" & Sh2RowCount) = data Then If Description = "" Then Description = .Range("A" & Sh2RowCount) Else Description = Description & ", " & .Range("A" & Sh2RowCount) End If End If Sh2RowCount = Sh2RowCount + 1 Loop End With .Range("B" & Sh1RowCount) = Description Sh1RowCount = Sh1RowCount + 1 Loop End With End Sub "gh" wrote: I have two spreadsheets. The first one has a column with numbers in it. The second one has a column with the same numbers and a description column as well. Each number can have more than one description. What I want to do do is iterate the rows in Sheet 1 and lookup the numbers in sheet 2. Then return all the descriptions to sheet 1 and put them in the cell next to the number. If there are multiple descriptions for a number we would like them separated by a comma. Is there a function for something like this? TIA |
All times are GMT +1. The time now is 02:01 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com