Help with vlookup cell VBA

Excelnoobisme

Board Regular
Joined
Nov 19, 2010
Messages
128
Hi,

I have a worksheet name A, on cell A1 is the date.

If i open another worksheet name B, there are pre-defined date on Column A(i.e. Mar 1 to 30) where in between each date there are 10 empty row.
Hence Mar 1 on cell A1, Mar 2 on cell A11 and Mar 3 on cell A21........

How can i write a marco that if i run on worksheet A, it will see the date on cell A1 and lookup to Sheet B and select 2 rows below after the same date.
(example date on cell A1 in worksheet A is Mar 3, so it will select cell A23 on worksheet B)

any help will be greatly appreciated.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hi. Try this

Code:
Sub test()
Dim Found As Range
Set Found = Sheets("B").Columns("A").Find(what:=Sheets("A").Range("A1").Value, LookIn:=xlValues, lookat:=xlWhole)
If Found Is Nothing Then
    MsgBox "Not found"
Else
    Application.Goto Found.Offset(2)
End If
End Sub
 
Upvote 0
Hi VOG, i need to copy data and paste 2 row after the date.

This is the original data in A.xlsx in Sheet(A).

<table style="padding-right: 2pt; padding-left: 2pt; font-size: 11pt; font-family: Calibri,Arial; background-color: rgb(255, 255, 255);" border="1" cellpadding="0" cellspacing="0"> <colgroup> <col style="width: 64px;"> <col style="width: 64px;"> <col style="width: 64px;"></colgroup> <tbody> <tr style="height: 18px;"> <td style="text-align: right;">3-Mar</td> <td> </td> <td>Amount </td></tr> <tr style="height: 18px;"> <td> </td> <td> </td> <td style="text-align: right;">$50 </td></tr> <tr style="height: 18px;"> <td> </td> <td> </td> <td style="text-align: right;">$60
</td></tr> <tr style="height: 18px;"> <td> </td> <td> </td> <td style="text-align: right;">$70 </td></tr> <tr style="height: 18px;"> <td> </td> <td>
</td> <td style="text-align: right;">$80
</td></tr></tbody></table>
In B.xlsx in Sheet(B), i wish my end result to be like this

<table style="padding-right: 2pt; padding-left: 2pt; font-size: 11pt; font-family: Calibri,Arial; background-color: rgb(255, 255, 255);" border="1" cellpadding="0" cellspacing="0"> <colgroup> <col style="font-weight: bold; width: 30px;"> <col style="width: 64px;"></colgroup> <tbody> <tr style="font-weight: bold; font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;"> <td> </td> <td>A</td></tr> <tr style="height: 18px;"> <td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">1</td> <td style="text-align: right;">1-Mar</td></tr> <tr style="height: 18px;"> <td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">2</td> <td> </td></tr> <tr style="height: 18px;"> <td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">3</td> <td> </td></tr> <tr style="height: 18px;"> <td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">4</td> <td> </td></tr> <tr style="height: 18px;"> <td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">5</td> <td> </td></tr> <tr style="height: 18px;"> <td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">6</td> <td> </td></tr> <tr style="height: 18px;"> <td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">7</td> <td> </td></tr> <tr style="height: 18px;"> <td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">8</td> <td> </td></tr> <tr style="height: 18px;"> <td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">9</td> <td> </td></tr> <tr style="height: 18px;"> <td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">10</td> <td> </td></tr> <tr style="height: 18px;"> <td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">11</td> <td style="text-align: right;">2-Mar</td></tr> <tr style="height: 18px;"> <td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">12</td> <td> </td></tr> <tr style="height: 18px;"> <td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">13</td> <td> </td></tr> <tr style="height: 18px;"> <td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">14</td> <td> </td></tr> <tr style="height: 18px;"> <td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">15</td> <td> </td></tr> <tr style="height: 18px;"> <td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">16</td> <td> </td></tr> <tr style="height: 18px;"> <td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">17</td> <td> </td></tr> <tr style="height: 18px;"> <td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">18</td> <td> </td></tr> <tr style="height: 18px;"> <td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">19</td> <td> </td></tr> <tr style="height: 18px;"> <td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">20</td> <td> </td></tr> <tr style="height: 18px;"> <td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">21</td> <td style="text-align: right;">3-Mar</td></tr> <tr style="height: 18px;"> <td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">22</td> <td> </td></tr> <tr style="height: 18px;"> <td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">23</td> <td> </td></tr> <tr style="height: 18px;"> <td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">24</td> <td style="text-align: right;">$50 </td></tr> <tr style="height: 18px;"> <td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">25</td> <td style="text-align: right;">$60 </td></tr> <tr style="height: 18px;"> <td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">26</td> <td style="text-align: right;">$70 </td></tr> <tr style="height: 18px;"> <td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">27</td> <td style="text-align: right;">$80 </td></tr> <tr style="height: 18px;"> <td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">28</td> <td> </td></tr> <tr style="height: 18px;"> <td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">29</td> <td> </td></tr> <tr style="height: 18px;"> <td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">30</td> <td> </td></tr></tbody></table>
 
Upvote 0
Maybe

Code:
Sub test()
Dim Found As Range
Set Found = Sheets("B").Columns("A").Find(what:=Sheets("A").Range("A1").Value, LookIn:=xlValues, lookat:=xlWhole)
If Found Is Nothing Then
    MsgBox "Not found"
Else
    Sheets("A").Range("C2:C5").Copy Destination:=Found.Offset(2)
End If
End Sub
 
Upvote 0
run time error....

dont i need to

Windows("B.xlsx").Activate
or
Windows("A.xlsx").Activate

as it's in 2 difference workbook
 
Upvote 0
Try

Code:
Sub test()
Dim Found As Range
Set Found = Workbooks("B.xls").Sheets("Sheet2").Columns("A").Find(what:=Workbooks("A.xls").Sheets("Sheet1").Range("A1").Value, LookIn:=xlValues, lookat:=xlWhole)
If Found Is Nothing Then
    MsgBox "Not found"
Else
    Workbooks("A.xls").Sheets("Sheet1").Range("C2:C5").Copy Destination:=Workbooks("B.xls").Sheets("Sheet2").Range(Found.Address).Offset(2)
End If
End Sub
 
Upvote 0
Run-Time error "9"



Set Found = Workbooks("B.xls").Sheets("Sheet2").Columns("A").Find(what:=Workbooks("A.xls").Sheets("Sheet1").Range("A1").Value, LookIn:=xlValues, lookat:=xlWhole)


was highlighted
</pre>
 
Upvote 0
One or more of the items in red does not exist

Rich (BB code):
Set Found = Workbooks("B.xls").Sheets("Sheet2").Columns("A").Find(what:=Workbooks("A.xls").Sheets("Sheet1").Range("A1").Value, LookIn:=xlValues, lookat:=xlWhole)
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,299
Members
452,904
Latest member
CodeMasterX

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