how to get multiple lookup values in one cell using vba code for static LookupValue, LookupRange , ColumnNumber, delimiter from different sheets

Aravind

For ex: I have two sheets Sheet 1 & Sheet 2

enter image description here

enter image description here

enter image description here

I'm using the below code, which is very slow and have to pass values. I need to built a code without passing values and look between the sheets. Kindly guide me how to do that. Thanks in advance

```
Function SingleCellExtract(LookupValue As String, LookupRange As Range, ColumnNumber As Integer, 
Char As String)
    Dim I As Long
Dim xRet As String
For I = 1 To LookupRange.Columns(1).Cells.Count
    If LookupRange.Cells(I, 1) = LookupValue Then
        If xRet = "" Then
            xRet = LookupRange.Cells(I, ColumnNumber) & Char
        Else
            xRet = xRet & "" & LookupRange.Cells(I, ColumnNumber) & Char
        End If
    End If
 Next
SingleCellExtract = Left(xRet, Len(xRet) - 1)
End Function
```
CDP1802

Take a look at Dictionary Objects

Option Explicit

Sub macro1()

    Dim dict As Object, lastrow As Long, r As Long, n As Long
    Dim key As String, t0 As Single: t0 = Timer
    Set dict = CreateObject("Scripting.Dictionary")
    
    With Sheets("Sheet2")
        lastrow = .Cells(.Rows.Count, "A").End(xlUp).row
        For r = 2 To lastrow
            key = Trim(.Cells(r, "A"))
            If dict.exists(key) Then
                dict(key) = dict(key) & "," & Trim(.Cells(r, "B"))
            ElseIf Len(key) > 0 Then
                dict(key) = Trim(.Cells(r, "B"))
            End If
        Next
    End With
  
    With Sheets("Sheet1")
        lastrow = .Cells(.Rows.Count, "A").End(xlUp).row
        For r = 2 To lastrow
            key = Trim(.Cells(r, "A"))
            If dict.exists(key) Then
                .Cells(r, "B") = dict(key)
                n = n + 1
            End If
        Next
    End With
    MsgBox n & " Rows updated", vbInformation, Format(Timer - t0, "0.0 secs")
  
End Sub

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Lookup multiple values from one cell

VBA code to return multiple lookup values in one comma separated works but crashes if there's an empty cell

How to get different time values from one cell and but it in different cells?

How to lookup multiple values based on multiple criteria in one cell?

Making one Array composed of multiple range values from different sheets in Excel VBA

How to take lookup values from different sheets and show appropriate result?

Multiple IF statements within VBA code to pull in different cell values from multiple columns based on another column.

How to split values from one cell to multiple cells using bash

How to get unique values from a specific column from multiple sheets in a separate sheet using Excel or Google sheets?

How to check cell values in different sheets using JavaScript and ExcelJS?

How to copy an entire sheets values as static into another sheet using vba

How to match the cell values and copy them from different sheets

Lookup Values in one column and if match add the values from a different column Google Script Google Sheets

How to get 5 biggest values from multiple sheets in Google Sheets?

Get values from other sheets in Excel using VBA

Excel VBA code (assigned to a button) to hide/unhide rows based on cell values across multiple sheets

How to lookup multiple highest values from one data reference?

Google Sheets:How to update a cell with the range of values in one column, based on the contents of another range of values in different column?

In matlab how can someone put the values from a single cell with multiple values within it seperated by a specific delimiter in a matrix?

Transfer cell values from different columns and sheets from multiple excel files with same structure into a single dataframe

How can I extract a specific substring from one cell using a list of specific values from a different column to return in a new cell?

How to split one column into multiple columns by delimiter (with different numbers of delimiter)

Write multiple values to one cell - VBA

How to add multiple string values to a cell in a excel sheet using vba

How do I sum the same cell from dynamic sheets in another cell in master sheet using vba?

Index and Match formula with multiple Lookup Values but for one cell

Excel2011 - Lookup and return multiple values into one cell BY DATE

How can I lookup in Google Sheets using using a regex match from two columns and one vlookup/ Array

How to get a list of a cell's font values in Excel using VBA