Vlookup in database for multiple cells

fher9728

New Member
Joined
Jan 9, 2020
Messages
33
Office Version
  1. 365
Platform
  1. Windows
Hi, its me again,

I have another problem, the thing is that I want to find the name of multiple Stores, I have the store id and I have the Stores Database in another worksheet, the the thing that I want is to run a macro that search me automatically every code that i put in a extensive table(many data that i put here daily), I'll give an example

1585185007512.png


What i want is when i put the code in column F, it appears me automatically the store name in column b , and the region in column c, but I want it in vba because using vlookup in too many cells will blow up my Workbook and need it to remain light, the database of Stores is in another Worksheet this is an example:
1585185406377.png

I want to get Store name and region

the code that I have until now is:
VBA Code:
Sub buscarnom()



Dim Cl As Range
   
   For Each Cl In Range("f2", Range("F" & Rows.Count).End(xlUp))
      If IsNumeric(Cl.Value) Then
         Cl.Offset(, 10).Value = Application.VLookup(C1.Value, Sheets("BD CLIENTES").Range("C3:D69"), 2, 0)
      Else
         Cl.Offset(, -3).Value = Application.VLookup(C1.Value, Sheets("BD CLIENTES").Range("C3:G69"), 4, 0)
      End If
         Next Cl
      
      End Sub

Second Part,

here I have another table and what I pretend to do is to delete rows with Status "Vencido"
1585185702548.png

But i want to be deleted the entire row, but only the ones with status "vencido" the rows with status vigente not,

Hope you may help me like last time, thank you
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
I think I was complicating the code … If we go back to your original code & slightly adjust it like below will work as well
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim cell As Range, Rg As Range
Set Rg = Sheets("BD CLIENTES").Range("B2").CurrentRegion

If Not Intersect(Target, Range("F:F")) Is Nothing Then
    For Each cell In Target
        If IsEmpty(cell) Then
            cell.Offset(, -4).Resize(, 2) = vbNullString
        Else
            cell.Offset(, -4) = Application.VLookup(cell.Value, Rg.Offset(, 1), 2, 0)
            cell.Offset(, -3) = Application.VLookup(cell.Value, Rg.Offset(, 1), 5, 0)
        End If
    Next
End If

End Sub
 
Upvote 0
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!


Cross posted at: Vlookup in database for multiple cells
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
I think I was complicating the code … If we go back to your original code & slightly adjust it like below will work as well
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim cell As Range, Rg As Range
Set Rg = Sheets("BD CLIENTES").Range("B2").CurrentRegion

If Not Intersect(Target, Range("F:F")) Is Nothing Then
    For Each cell In Target
        If IsEmpty(cell) Then
            cell.Offset(, -4).Resize(, 2) = vbNullString
        Else
            cell.Offset(, -4) = Application.VLookup(cell.Value, Rg.Offset(, 1), 2, 0)
            cell.Offset(, -3) = Application.VLookup(cell.Value, Rg.Offset(, 1), 5, 0)
        End If
    Next
End If

End Sub


Hi, it works perfect!! the only problem that I have now is that I cant delete any row because it gives this error
1585328298661.png

1585328316528.png

how can I do in this case?
 
Upvote 0
I didn't try that before :) … Anyway, I made some adjustment to the code to accept row insert/delete as per the below file


VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Columns.Count > 15 Then Exit Sub

Dim cell As Range, Rg As Range
Set Rg = Sheets("BD CLIENTES").Range("B2").CurrentRegion

If Not Intersect(Target, Range("F:F")) Is Nothing Then
    For Each cell In Target
        If IsEmpty(cell) Then
            Cells(cell.Row, 2).Resize(, 2) = vbNullString
        Else
            Cells(cell.Row, 2) = Application.VLookup(cell.Value, Rg.Offset(, 1), 2, 0)
            Cells(cell.Row, 3) = Application.VLookup(cell.Value, Rg.Offset(, 1), 5, 0)
        End If
    Next
End If

End Sub
 
Upvote 0
I didn't try that before :) … Anyway, I made some adjustment to the code to accept row insert/delete as per the below file


VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Columns.Count > 15 Then Exit Sub

Dim cell As Range, Rg As Range
Set Rg = Sheets("BD CLIENTES").Range("B2").CurrentRegion

If Not Intersect(Target, Range("F:F")) Is Nothing Then
    For Each cell In Target
        If IsEmpty(cell) Then
            Cells(cell.Row, 2).Resize(, 2) = vbNullString
        Else
            Cells(cell.Row, 2) = Application.VLookup(cell.Value, Rg.Offset(, 1), 2, 0)
            Cells(cell.Row, 3) = Application.VLookup(cell.Value, Rg.Offset(, 1), 5, 0)
        End If
    Next
End If

End Sub
Works perfect, thankyou so much, I appreciate the effort you did to help me!
 
Upvote 0
Hi @mse330 , I got a new problem with the new code :( it doesn't search anything when I do copypaste in the store ID in column F, how can it be solved?
 
Upvote 0

Forum statistics

Threads
1,214,926
Messages
6,122,306
Members
449,079
Latest member
juggernaut24

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