Загрузка данных


Private Sub CommandButton1_Click()
    If ListBox1.ListIndex = -1 Then
        MsgBox "Выберите товар"
        Exit Sub
    End If
    
    Dim товар As String
    товар = ListBox1.Value
    
    Dim цена As Variant
    цена = Application.VLookup(товар, Sheets(ActiveSheet.Name).Range("A:B"), 2, False)
    
    If IsError(цена) Then
        MsgBox "Цена не найдена"
    Else
        UserForm2.TextBox1.Value = цена
        UserForm2.ListBox1.AddItem товар
        UserForm2.Show
    End If
End Sub