logo elektroda
logo elektroda
X
logo elektroda

Excel search function vertically - Create a function search vertically in VBA

Raptor26 5103 4
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 16213743
    Raptor26
    Level 10  
    I would like to create a vertical search function with parameters in VBA
    I have 2 sheets.
    Database - contains account numbers assigned to branch numbers
    Sheet - contains account numbers and amounts but, branch number is missing.

    Just inserting the search function vertically gives me nothing.
    I need the same thing but in VBA.
    I tried to create a macro but VLOOKUP code is in marco and I have no idea how to make parameters from this function.
  • ADVERTISEMENT
  • #2 16213816
    cbrman
    Level 27  
    I don't really understand what you want to achieve.
    After all, the vertical search function works well in this example, and vlookup (with VBA) has the same arguments as the "normal" search formula.
  • ADVERTISEMENT
  • #3 16213992
    Raptor26
    Level 10  
    That this function is only to be a fragment of the whole code - the procedure that I will use in the worksheet.
    Then I will generate xmla.
    I know how to do it because I have a pattern but I have no idea how to create such a function.
  • ADVERTISEMENT
  • #5 16214299
    Raptor26
    Level 10  
    That's exactly what I meant.
    I just wanted to additionally introduce row and column variables for the range through the If Else or For statement.
    I found the following code on the English page.

    Sub ADDCLM ()
    On Error Resume Next
    Dim Dept_Row As Long
    Dim Dept_Clm As Long
    Table1 = Sheet1.Range ("A3: A13") 'Employee_ID Column from Employee table
    Table2 = Sheet1.Range ("H3: I13") 'Range of Employee Table 1
    Dept_Row = Sheet1.Range ("E3"). Row 'Change E3 with the cell from where you need to start populating the Department
    Dept_Clm = Sheet1.Range ("E3"). Column
    For Each cl In Table 1
    Sheet1.Cells (Dept_Row, Dept_Clm) = Application.WorksheetFunction.VLookup (cl, Table2, 2, False)
    Dept_Row = Dept_Row + 1
    Next cl
    MsgBox "Done"
    End Sub

    I converted it to my needs and it works, but I have to automate it, i.e. introduce variables Row, Column for Table 1 and Table 2.
    Ultimately, the function is to check line by line, but also to monitor when it turns out that there is a new account that is not included in the Database table
ADVERTISEMENT