Hi,
I have some troubles with code and logic for my macro.
I have Sheet1 with numbers.
I have Sheet2, where for each number for Sheet1 data is scraped from web, then certain values are searched for it Sheet2, after being found - data is being deleted, and new data, for next number from Shee1 is scraped.
The string im searcing for in Sheet2 is "Quota number" - since in this Sheet there may occur, multiple time or none, "Quota number: XYZ" (in one cell) - I want to copy such cell and paste it next to the number from Sheet1. However, if value is found more than once I would like to have it pasted in new, added row, below the number pasted with first match. Example:
1) Only one match
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Value Match
45678 0110
12345 0990
34567 0550 </code>
2) More than one match for 12345
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Value Match
45678 0110
12345 0990
12345 0770 '<--- second match in Sheet2
34567 0550 </code>
Please note, that VLOOKUP wont't work, since numbers from Sheet1 do not appear in Sheet2 - there is only data scraped with those numbers used in URL.
I have prepared a code using Match function, but I was not aware that "Quoata number" may appear more than once, and now I have no idea how to use FindNext + pasting found values in new rows (only first found value should be pasted next to the number)
Currently, the codes looks as follows:
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">ws2.Activate
For Each c In ws1.UsedRange.Columns("A").Cells 'for each number in ws1 data is scraped to ws2, but I'm not pasting the hole code below
If Not IsError(Application.Match("*Quota number:*", Range("A:A"), 0)) Then
Quota = Application.Match("*Quota number:*", Range("A:A"), 0)
QuotaVal = ActiveSheet.Cells(Quota, 1)
ws1.Cells(c.Row, 2).Value = QuotaVal
End If
Next c</code>
I have some troubles with code and logic for my macro.
I have Sheet1 with numbers.
I have Sheet2, where for each number for Sheet1 data is scraped from web, then certain values are searched for it Sheet2, after being found - data is being deleted, and new data, for next number from Shee1 is scraped.
The string im searcing for in Sheet2 is "Quota number" - since in this Sheet there may occur, multiple time or none, "Quota number: XYZ" (in one cell) - I want to copy such cell and paste it next to the number from Sheet1. However, if value is found more than once I would like to have it pasted in new, added row, below the number pasted with first match. Example:
1) Only one match
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Value Match
45678 0110
12345 0990
34567 0550 </code>
2) More than one match for 12345
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Value Match
45678 0110
12345 0990
12345 0770 '<--- second match in Sheet2
34567 0550 </code>
Please note, that VLOOKUP wont't work, since numbers from Sheet1 do not appear in Sheet2 - there is only data scraped with those numbers used in URL.
I have prepared a code using Match function, but I was not aware that "Quoata number" may appear more than once, and now I have no idea how to use FindNext + pasting found values in new rows (only first found value should be pasted next to the number)
Currently, the codes looks as follows:
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">ws2.Activate
For Each c In ws1.UsedRange.Columns("A").Cells 'for each number in ws1 data is scraped to ws2, but I'm not pasting the hole code below
If Not IsError(Application.Match("*Quota number:*", Range("A:A"), 0)) Then
Quota = Application.Match("*Quota number:*", Range("A:A"), 0)
QuotaVal = ActiveSheet.Cells(Quota, 1)
ws1.Cells(c.Row, 2).Value = QuotaVal
End If
Next c</code>