Using Vba to acquire lookup results in one cell

Sazzle14

New Member
Joined
Apr 12, 2011
Messages
20
Hi I used the formula below in trying to solve a puzzle I have, and it has got really close to what I need. It presented the results in col 1 and 2 below (C and D in your formula). However, What I need is to get the results separately i.e. Results for "7" in one cell in the spreadsheet and Results for "8" in another and the same with 9. So I need the formula to specify what it is looking for in column "BoX" but deliver the results in the same way it did for Column 1 and 2. I.e. it brings back multiple values with either a "," to separate or if possible a soft return {alt & Enter}
I know I am asking a lot but would so appreciate your help, I have tried Index and other VBA solutions and not having much luck.

BoxNameColumn1Column2
7Corel7Corel , Steph , Jen , Amanda
7Steph8Carol, Amer, Vicky, Charlotte, David
7Jen9Kam, Gwen , Raj, David, Mark , Emma
7Amanda
8Carol
8Amer
8Vicky
8Charlotte
8David
9Kam
9Gwen
9Raj
9David
9Mark
9Emma

<tbody>
</tbody>





quote_icon.png
Originally Posted by Tinbendr
Welcome to the board!

Code:
Code:
Sub MergeGroups()
 Dim WS As Worksheet
 Dim Rng As Range
 Dim LastRow As Long
 Dim Ctr As Long
 Dim Temp$
     'Result Row
     Ctr = 1

     Set WS = ActiveWorkbook.ActiveSheet
     With WS
         'Last row of column A with data.
         LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

         'Loop through each item in Col A.
         For Each Rng In Range("A2:A" & LastRow)
             'Compare to next item down.  If equal build user string.
             If Rng.Offset(1, 0).Value = Rng.Value Then
                 Temp$ = Temp$ & Rng.Offset(0, 1).Value & ", "
             Else
                 'Servers no longer match.
                 Ctr = Ctr + 1
                 'Add last match
                 Temp$ = Temp$ & Rng.Offset(0, 1).Value
                 'Post to Col C & D.
                 .Range("C" & Ctr).Value = Rng.Value
                 .Range("D" & Ctr).Value = Temp$
                 'Clear Temp$
                 Temp$ = ""
             End If
         Next
     End With
 End Sub
 
Last edited by a moderator:
Just typed it in - although now I feel you are probably shaking your head in disbelief - eek!

Code:
With CreateObject("scripting.dictionary")
      For Each Cl In Range("F2", Range("F" & Rows.Count).End(xlUp))
         If Not .exists(Cl.Value) Then
            .Add Cl.Value, Cl.Offset(, 1).Value
         Else
            .Item(Cl.Value) = .Item(Cl.Value) & Chr(10) & Cl.Offset(, 1).Value
         End If
      Next Cl
      Worksheet("Sheet1").Range("j5").Value = .Item(1)
      Worksheet("Sheet1").Range("K5").Value = .Item(2)
      Worksheet("Sheet1").Range("l5").Value = .Item(3)
      Worksheet("Sheet1").Range("j6").Value = .Item(4)
      Worksheet("Sheet1").Range("k6").Value = .Item(5)
      Worksheet("Sheet1").Range("l6").Value = .Item(6)
      Worksheet("Sheet1").Range("j7").Value = .Item(7)
      Worksheet("Sheet1").Range("k7").Value = .Item(8)
      Worksheet("Sheet1").Range("l7").Value = .Item(9)
   End With
End Sub
 
Last edited by a moderator:
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
You've missed the s from the end of worksheets
 
Upvote 0
Oh my goodness yes I have!!! Yes it is perfect!! thank you so so so much and thank you for being so patient!!
 
Upvote 0

Forum statistics

Threads
1,216,100
Messages
6,128,827
Members
449,470
Latest member
Subhash Chand

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