• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

vlookup using VBA copy and paste selection to the right of looked up value

twells

New Member
I am a VBA beginner and I am trying to take a list of checks and lookup each check by check number in a worksheet and if found, verify the amount is the same and then I would like to copy and paste the check date, check number, and amount in the appropriate columns to the right of where the looked up check number was found. Hope that makes sense. I have attached the file below. Thanks for the help.


https://www.dropbox.com/s/1q3bbt8yuswduyj/Cleared%20Checks.xlsm
 
Hi, twells!


First of all welcome to Chandoo's website Excel forums. Thank you for your joining us and glad to have you here.


As a starting point I'd recommend you to read the green sticky topics at this forums main page. There you'll find general guidelines about how this site and community operates (introducing yourself, posting files, netiquette rules, and so on).


Among them you're prompted to perform searches within this site before posting, because maybe your question had been answered yet.


Feel free to play with different keywords so as to be led thru a wide variety of articles and posts, and if you don't find anything that solves your problem or guides you towards a solution, you'll always be welcome back here. Tell us what you've done, consider uploading a sample file as recommended, and somebody surely will read your post and help you.


And about questions in general...


If you haven't performed yet the search herein, try going to the topmost right zone of this page (Custom Search), type the keywords used in Tags field when creating the topic or other proper words and press Search button. You'd retrieve many links from this website, like the following one(s) -if any posted below-, maybe you find useful information and even the solution. If not please advise so as people who read it could get back to you as soon as possible.


And about this question in particular...


Give a look at this file:

https://dl.dropboxusercontent.com/u/60558749/vlookup%20using%20VBA%20%26%20copy%20and%20paste%20selection%20to%20the%20right%20of%20looked%20up%20valuevlook%20-%20Cleared%20Checks%20%28for%20twells%20at%20chandoo.org%29.xlsm


I added to columns to your input check list so as to reflect the clearing status and the row related (via a link). I too suggest you to change the ListOfChecks named range definition to make it dynamic as follows:

=DESREF('0513'!$M$10;;;CONTARA('0513'!$M:$M)-1;5) -----> in english: =OFFSET('0513'!$M$10,,,COUNTA('0513'!$M:$M)-1,5)

Then I'd use this range and the table (Table35) in this code for the command button click event:

-----

Option Explicit

Private Sub CommandButton1_Click()
' constants
Const ksWS = "0513"
Const ksList = "ListOfChecks"
Const ksTable = "Table35"
Const ksCleared = "Ok"
Const ksHyperlinkFormula = "=HYPERLINK(""#XXX"",YYY)"
Const ksWildcard1 = "XXX"
Const ksWildcard2 = "YYY"
' declarations
Dim rngL As Range, rngT As Range, c As Range
Dim lCheckNo As Long, dCheckDate As Date, cCheckAmount As Currency
Dim I As Long, J As Integer, A As String
' start
' define
With Worksheets(ksWS)
Set rngL = .Range(ksList)
Set rngT = Range(ksTable)
End With
' clear
With rngL
Range(.Columns(.Columns.Count - 1), .Columns(.Columns.Count)).Select
Selection.ClearContents
End With
' process
With rngL
For I = 1 To .Rows.Count
' lookup
Set c = rngT.Columns(3).Find(.Cells(I, 2).Value, , , xlWhole)
' found?
If Not c Is Nothing Then
' row (w/o title)
J = c.Row - 1
' equal amount?
If .Cells(I, 3).Value = -rngT.Cells(J, 4).Value Then
' register
rngT.Cells(J, 7).Value = .Cells(I, 1).Value
rngT.Cells(J, 8).Value = .Cells(I, 2).Value
rngT.Cells(J, 9).Value = .Cells(I, 3).Value
' mark
.Cells(I, 4).Value = ksCleared
A = rngT.Cells(J, 7).Address(False, False, xlA1)
.Cells(I, 5).Formula = _
Replace(Replace(ksHyperlinkFormula, ksWildcard1, A), _
ksWildcard2, _
J + 1)
End If
End If
Next I
End With
' end
Set c = Nothing
Set rngT = Nothing
Set rngL = Nothing
Beep
End Sub

-----


Regarding your table (which I didn't modify) IMHO columns H and I are redundant since the number and the amount of the received check should always match with the list, otherwise it won't be cleared. If you agree in deleting these columns you may modify actual column J formula from:

=I2+D2

to

=SI(ESBLANCO(H2);0;-D2)+D2 -----> in english: =IF(ISBLANK(H2),0,-D2)+D2


Just advise if any issue.


Regards!
 
That works great. Thank you! I have been searching for days trying to figure this out. I have never used a forum before but thought I would try it and I am glad I did. Thank you so much for your help.
 
Hi, twells!

Glad you solved it. Thanks for your feedback and for your kind words too. And welcome back whenever needed or wanted.

Regards!
 
Back
Top