Search through column(s) once found a match, extract data from other column(s)

PoPoRa

New Member
Joined
May 24, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi all, I have been lurking around these forums to see how to properly ask a question... So here goes...
For example, I have this data set named below and I want to match some values to columns 'ID1' , 'ID2' and 'ID3'. These values are called 'Alarm' with values '2103, 2107, 2805, 2152, 2810...'. After matching 1 of the value, it will copy the data of the same rows of columns 'Data1.Direction[0]' , 'Data1.Count[0]' , 'Data1.Preiod[0]' , 'Data2.Direction[0]' , 'Data2.Count[0]' , 'Data2.Preiod[0]'. It should copy data from its row of the matched ID as well as 9 more rows above (so total 10 rows). It will then create a new sheet named 'Alarm' and paste the data there side by side without empty columns.
FYP.xlsx
ABCDEFGHIJKLMNOPQ
20021116011364959691131985938
30005911366459661132105944
40005811368059691132225960
55640005711369559651132345957
60005611370959641132455954
70005511372459681132575952
80005411373959691132695957
90005311375359881132815952
100005211376759801132925951
110005111378159791133045950
120005011379559771133165953
130004911380959811133285970
140004811382259851133395968
150004711383659751133515961
160004611384959781133635969
170004511386259811133745965
180215204411387559981133865969
190004311388859981133985965
200004211390059891134105964
218180004111391359941134215967
220004011392659941134335970
230003911393759961134455988
240003811395059901134575980
250003711396159881134685980
260003611397359911134805977
270028103511398559991134925981
280003411399660081135035985
290003311400760031135155975
300003211401860051135275978
310003111403060021135385981
320003011404060081135505996
330002911405160031135625998
342103002811406160041135735987
350002711407260221135855995
360002611408260141135975994
370002511409260171136095996
380045102411410260211136205990
390002311411160281136325988
400002211412160371136445991
410002111413060351136555999
420002011413960311136676008
430001911414960251136796003
442107001811415860291136906005
Sheet1

The end product should look like below,
FYP.xlsx
ABCDEFGH
1ID 2MoveData1.Direction[0]Data1.Count[0]Data1.Preiod[0]Data2.Direction[0]Data2.Count[0]Data2.Preiod[0]
25311375359881132815952
35211376759801132925951
45111378159791133045950
55011379559771133165953
64911380959811133285970
74811382259851133395968
84711383659751133515961
94611384959781133635969
104511386259811133745965
1121524411387559981133865969
Alarm


And if possible, I hope that the code can in a way that I am able to change code for the searched values (2103 can be changed to 8181) and the name of the copied data (Data1.Direction[0] can be changed to something else like Port[1]. This is because I want to reuse the code for doing the same procedure but different searched values and copied data.

Hope this isnt too much too ask... thanks all.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Edit: Just realised I missed out row 1 of sheet 1 in the XL2BB
FYP.xlsx
ABCDEFGHIJKLMNOPQ
1ID1ID2ID3MoveData1.Direction[0]Data1.Count[0]Data1.Preiod[0]Data2.Direction[0]Data2.Count[0]Data2.Preiod[0]
20021116011364959691131985938
30005911366459661132105944
40005811368059691132225960
55640005711369559651132345957
60005611370959641132455954
70005511372459681132575952
80005411373959691132695957
90005311375359881132815952
100005211376759801132925951
110005111378159791133045950
120005011379559771133165953
130004911380959811133285970
140004811382259851133395968
150004711383659751133515961
160004611384959781133635969
170004511386259811133745965
180215204411387559981133865969
190004311388859981133985965
200004211390059891134105964
218180004111391359941134215967
220004011392659941134335970
230003911393759961134455988
240003811395059901134575980
250003711396159881134685980
260003611397359911134805977
270028103511398559991134925981
280003411399660081135035985
290003311400760031135155975
300003211401860051135275978
310003111403060021135385981
320003011404060081135505996
330002911405160031135625998
342103002811406160041135735987
350002711407260221135855995
360002611408260141135975994
370002511409260171136095996
380045102411410260211136205990
390002311411160281136325988
400002211412160371136445991
410002111413060351136555999
420002011413960311136676008
430001911414960251136796003
442107001811415860291136906005
Sheet1
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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