Search & Fill

kashyap

Board Regular
Joined
Mar 28, 2009
Messages
173
I have some data something like below

<table width="64" border="0" cellpadding="0" cellspacing="0"><col style="width:48pt" width="64"> <tbody><tr style="height:15.0pt" height="20"> <td style="height:15.0pt;width:48pt" width="64" height="20">asd</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" height="20">knbiu1</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" height="20">knbiu2</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" height="20">knbiu3</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" height="20">knbiu42</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" height="20">knbiu8</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" height="20">mno</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" height="20">dfg</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" height="20">try</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" height="20">fngthj</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" height="20">htydfg</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" height="20">xyz</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" height="20">dfgo</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" height="20">dfglkn</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" height="20">ergjjg</td> </tr> </tbody></table>
.. and search items something as below in a different sheet

<table width="64" border="0" cellpadding="0" cellspacing="0"><col style="width:48pt" width="64"> <tbody><tr style="height:15.0pt" height="20"> <td style="height:15.0pt;width:48pt" width="64" height="20">asd</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" height="20">mno</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" height="20">xyz</td> </tr> </tbody></table>
trying to get output like below with macro

<table width="128" border="0" cellpadding="0" cellspacing="0"><col style="width:48pt" span="2" width="64"> <tbody><tr style="height:15.0pt" height="20"> <td style="height:15.0pt;width:48pt" width="64" height="20">asd</td> <td style="width:48pt" width="64">asd</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" height="20">knbiu1</td> <td>asd</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" height="20">knbiu2</td> <td>asd</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" height="20">knbiu3</td> <td>asd</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" height="20">knbiu42</td> <td>asd</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" height="20">knbiu8</td> <td>asd</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" height="20">mno</td> <td>mno</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" height="20">dfg</td> <td>mno</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" height="20">try</td> <td>mno</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" height="20">fngthj</td> <td>mno</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" height="20">htydfg</td> <td>mno</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" height="20">xyz</td> <td>xyz</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" height="20">dfgo</td> <td>xyz</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" height="20">dfglkn</td> <td>xyz</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" height="20">ergjjg</td> <td>xyz</td> </tr> </tbody></table>
can anyone help me with this pls..

Thank you..
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
kashyap,


Sample worksheets before the macro:


Excel Workbook
A
1asd
2mno
3xyz
4
Sheet2





Excel Workbook
AB
1asd
2knbiu1
3knbiu2
4knbiu3
5knbiu42
6knbiu8
7mno
8dfg
9try
10fngthj
11htydfg
12xyz
13dfgo
14dfglkn
15ergjjg
16
Sheet1





After the macro:


Excel Workbook
AB
1asdasd
2knbiu1asd
3knbiu2asd
4knbiu3asd
5knbiu42asd
6knbiu8asd
7mnomno
8dfgmno
9trymno
10fngthjmno
11htydfgmno
12xyzxyz
13dfgoxyz
14dfglknxyz
15ergjjgxyz
16
Sheet1





Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


Code:
Option Explicit
Sub SearchAndFill()
' hiker95, 05/11/2011
' http://www.mrexcel.com/forum/showthread.php?t=549261
Dim w1 As Worksheet, w2 As Worksheet
Dim c As Range, FR As Long, LR As Long
Application.ScreenUpdating = False
Set w1 = Worksheets("Sheet1")
Set w2 = Worksheets("Sheet2")
w1.Columns(2).ClearContents
For Each c In w2.Range("A1", w2.Range("A" & Rows.Count).End(xlUp))
  FR = 0
  On Error Resume Next
  FR = Application.Match(c, w1.Columns(1), 0)
  On Error GoTo 0
  If FR > 0 Then w1.Cells(FR, 2) = c
Next c
LR = w1.Cells(Rows.Count, 1).End(xlUp).Row
w1.Range("B1:B" & LR).SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
With w1.Range("B1:B" & LR)
  .Value = .Value
End With
w1.Activate
Application.ScreenUpdating = True
End Sub


Then run the SearchAndFill macro.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,550
Messages
6,179,459
Members
452,915
Latest member
hannnahheileen

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