vba to replace Vlookup

cizzett

Board Regular
Joined
Jan 10, 2019
Messages
121
OK Guys so I have been using this formula and it works perfectly, the issue im running into is that the column is a date which can be put in in several ways and I need to see it exactly as it is entered, so I am changing the column to "Text Format" but that means my formula will no longer work

Can someone guide me on the best way to VBA code this to function similarly?

It can be run with another macro so it wont need to be a change event or anything like that.

Code:
=IFERROR(VLOOKUP($A3, PD_Table,18,FALSE),"")

Thanks in advance for any help.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
I should also mention the two sheets are in the same workbook and both ranges are tables.

Today sheet with TodayTable on it and Prev Day Sheet with PD_Table on it

Both are identical layouts and column a is named Key and has the unique identifier while columns 17 and 18 I want to return the values from PD_Table to TodayTable if Key matches both tables
 
Upvote 0
So this is what ive come up with playing with web finds, I think this is on the right direction but so far it is overwriting my title of the table column which my table begins on row 2 and the databody begins on row 3. I do not want to overwrite my column header and it is also not returning the dates from column 17 but instead the results of column A are being pasted into column 17.

I really hope you can help me find the right direction.

Thanks in advance.


Code:
Sub LookDT()


Dim WS As Worksheet: Set WS = Sheets("Today")
Dim Ps As Worksheet: Set Ps = Sheets("Prev Day")
Dim lastrow, lastrow2, i As Long
Dim Searchfor, j, inarr, searcharr, outarr As Variant


lastrow = WS.Cells(Rows.Count, "A").End(xlUp).Row
lastrow2 = Ps.Cells(Rows.Count, "A").End(xlUp).Row
inarr = Range(Cells(1, 1), Cells(lastrow, 1))


' load variant array with sercha variables
searcharr = Range(Cells(1, 1), Cells(lastrow, 26))


' define an output aray
outarr = Range(Cells(1, 1), Cells(lastrow, 1))
On Error Resume Next


For i = 3 To lastrow2
 For j = 3 To lastrow
 Searchfor = searcharr(i, 1)
 If inarr(j, 1) = Searchfor Then
  outarr(i, 17) = inarr(j, 17)
  Exit For
 End If
 Next j
Next i
' writeout the output array
Range(Cells(1, 17), Cells(lastrow, 17)) = outarr


End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

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