Excel VBA

iretex

New Member
Joined
Nov 16, 2017
Messages
1
Please I need help with my code,

I wanted to lookup a reference from a range and if found write a value in the last empty cell on the row reference of the Matching value in my data range.

Code:
Option ExplicitDim d As Variant, SN As Integer


Sub Button1_Click()


Dim a As Variant, b As Variant, c As Variant


Dim looksn As Variant, FoundCell As Range


Dim Ans As Integer, NR As Long




Dim wkb1    As Workbook, SN As Range, wsMaster As Worksheet


 
Set wkb1 = ActiveWorkbook




'wkb1.Sheets("Sheet1").Range(sn) = looksn




'Sheets("Sheet1").Range("j8").Value = looksn


    On Error GoTo MyErrorHandler:


  'result = [VLOOKUP(Input!A2, Data!A1:X200, 5, FALSE)]
 
    a = Application.WorksheetFunction.VLookup(Sheets("sheet1").Range("I5"), Sheets("Sheet2").Range("Db"), 4, 0)
    b = Application.WorksheetFunction.VLookup(Sheets("sheet1").Range("I5"), Sheets("Sheet2").Range("Db"), 6, 0)
    c = Application.WorksheetFunction.VLookup(Sheets("sheet1").Range("I5"), Sheets("Sheet2").Range("Db"), 2, 0)
    d = Sheets("sheet1").Range("I5")
      
MyErrorHandler:
    
    'If IsError(a) Then
     If Err.Number = 1004 Then
     MsgBox "Shipment Cannot go, return to the Warehouse for proper documentation", vbCritical: Exit Sub
    End If
    
    'Display the matching values
          
    Sheet1.Range("J8").Value = a
    Sheet1.Range("J10").Value = b
    Sheet1.Range("J12").Value = c
    Sheet1.Range("J14").Value = d
    
    Ans = MsgBox("Are the details correct? Will you like to go ahead and checkout?", vbYesNoCancel)
    
    Select Case Ans
    
          Case vbYes
  '       ...[code if Ans is Yes]...
  Set wsMaster = ThisWorkbook.Sheets("Sheet2")
  
  NR = wsMaster.Range("A" & wsMaster.Rows.Count).End(xlUp).Row + 1
  
  'Call execute
  
  'Cells(FoundCell.Row, NR).Value = "checkout"
  
    'Call execute
    
          Case vbNo
  '       ...[code if Ans is No]...
    Exit Sub
        
        Case vbCancel
        
    Exit Sub
    
    
      End Select
    
    
    
    
    'WorksheetFunction.VLookup(Me.txtUsername.Value, Range("UserLogin"), 4, 0)
    
End Sub




Sub execute()


        Dim wb As Workbook
        Dim ws As Worksheet
        Dim FoundCell As Range
        Set wb = ActiveWorkbook
        Set ws = ActiveSheet


            'Const WHAT_TO_FIND As String = "Bingo"
            Sheets("Sheet1").Range("I5") = SN


            'Set FoundCell = ws.Range("A:A").Find(What:=WHAT_TO_FIND)
            Set FoundCell = Sheets("Sheet2").Range("Db").Find(What:=SN)
            If Not FoundCell Is Nothing Then
                MsgBox (SN & " found in row: " & FoundCell.Row)
            Else
                MsgBox (SN & " not found")
            End If
End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

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