VBA to fill a cell based on adjacent cell

PhantomOak

New Member
Joined
Apr 20, 2011
Messages
31
I have a userform that I want to input an invoice number, a vendor; I want to look for values in column A, and column B, and if they match, write to an adjacent cell (but first ask for conformation)

Right now it looks up the Invoice number in any cell in Table2 and writes offset to that value (no good).
Also, it only looks up the invoice number, and not the invoice and vendor (no good).

I have this so far
Code:
Private Sub CommandButton4_Click()

     
    Dim test1 As String
    Dim FoundRange As Range
     
    test1 = PaidInvoice.Value
    Worksheets("Invoices").Activate
     
    Set FoundRange = Sheets("Invoices").Cells.Find(what:=test1, LookIn:=xlFormulas, lookat:=xlWhole)
     
    If FoundRange Is Nothing Then
        MsgBox "No Invoice Found - (Invoice Number must match a previously recorded invoice)", vbExclamation, "Invoice Log"
        Me.PaidInvoice.SetFocus
    Else
        Dim Answer As String
        Dim MyNote As String

        'Place your text here
        MyNote = "Invoice '" & PaidInvoice.Value & " " & FoundRange.Offset(0, 1).Value & "'" & " will be marked 'PAID' : Continue?"

    'Display MessageBox
        Answer = MsgBox(MyNote, vbQuestion + vbYesNo, "Correct Invoice?")

        If Answer = vbNo Then
            Me.PaidInvoice.SetFocus
        Else
            PaidInvoice.Text = FoundRange.Value
            FoundRange.Offset(0, 7).Value = "Yes"
            FoundRange.Offset(0, 8).Value = Format(Now, "mm/dd/yy")
        End If

    End If
    

End Sub

Help :)
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Can anyone help :biggrin:

I am never sure when to bump something, but I was hoping it would be straight forward

Thanks guys!
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,703
Members
452,938
Latest member
babeneker

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