VBA Matching value in a range and return other cell values

Jasesair

Active Member
Joined
Apr 8, 2015
Messages
282
Office Version
  1. 2016
I didn't think this would be difficult...but perhaps I'm not thinking clearly.

I have values in cells H8:K8 from sheet 'Data Entry'. In sheet 'Results', I'm wanting to match A1 with A1's unique value in column F (it's long but if a range is needed, then F3:F6000). Once matched, I'd like the H8:K8 'Data Entry' cells to be returned in column H:K in the matched row in the 'Results' sheet. I hope that's making sense - I'm sure I could have explained that far better!!!

Is this possible with a little VBA?
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Is this possible with a little VBA?
It should be possible without vba. Is that acceptable?

Is this what you mean? If not, instead of us guessing the data and layout, could you give us a small set of dummy data and the expected results with XL2BB so that we know exactly what you have, where and what you want, and where?

Jaseair.xlsm
FGHIJK
1
2
3a803326933389
4b256869559838
5c932426798439
6d977539653505
7e813746184154
8f872457152906
9g913254488330
10h987530494244
11i987563296633
12j582575268572
13k890782272791
14l990793844135
15m258825483575
16n348756246784
17o424858199598
18p298644968592
19q857869365914
Data Entry



Jaseair.xlsm
ABCDEFGHIJK
1f872457152906
2c932426798439
Results
Cell Formulas
RangeFormula
H1:K2H1=INDEX('Data Entry'!H$3:H$6000,MATCH($A1,'Data Entry'!$F$3:$F$6000,0))
 
Upvote 0
I liked the idea of index-match but I can't even get that to work. The answer (index) is simply going to be H8 from the 'Data Entry' sheet in this case. My other issue with index-matching is the document is going to be huge if that's the method I go with. Just in this case alone, I'd have to have about 24000 index-match formulas. I'm not sure how to use XL2BB. I'll have a play though.
 
Upvote 0
I think with the volume of index-match formulas needed, it's going to be far better to run a macro. Is this a possibility?
 
Upvote 0
It sounded like my results shown in post #2 are not what you wanted so can you show us some sample data and expected results? It would be pointless developing code that does not produce the results you want. ;)
 
Upvote 0
I wasn't able to download XL2BB at work so it has to be images. I'm essentially trying to transpose the values in Data Entry into the Results sheet, as one row, all based on the unique match of A1 in column F. Each row of values in Data Entry would ideally transpose over into the correct Results row.
 

Attachments

  • 1.png
    1.png
    30.3 KB · Views: 44
  • 2.png
    2.png
    155 KB · Views: 43
Upvote 0
I'm essentially trying to transpose the values in Data Entry into the Results sheet, as one row, all based on the unique match of A1 in column F. Each row of values in Data Entry would ideally transpose over into the correct Results row.
Like this?

VBA Code:
Sub ToOneRow()
  Dim Results As Variant
  Dim rngData As Range, rngFound As Range
 
  With Sheets("Data Entry")
    Set rngData = .Range("H8:K" & .Range("H:K").Find(what:="*", LookIn:=xlValues, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row)
  End With
  Results = Split(Join(Application.Transpose(Evaluate( _
            rngData.Columns(1).Address(External:=True) & "&""@""&" & _
            rngData.Columns(2).Address(External:=True) & "&""@""&" & _
            rngData.Columns(3).Address(External:=True) & "&""@""&" & _
            rngData.Columns(4).Address(External:=True))), "@"), "@")
  With Sheets("Results")
    Set rngFound = .Columns("F").Find(what:=.Range("A1").Value, LookAt:=xlWhole)
    If Not rngFound Is Nothing Then
      rngFound.Offset(, 2).Resize(, UBound(Results) + 1).Value = Results
    Else
      MsgBox .Range("A1").Value & " not found in column F"
    End If
  End With
End Sub

If unable to use XL2BB you can just copy from Excel to your post like this. At least that can be copied at this end to save what could be a lot of typing which many helpers might just bypass. ;)

HIJK
8​
2​
3​
2​
9​
2​
1​
10​
11​
3​
 
Last edited:
Upvote 0
Solution
Peter, this is so, so good!!! I've tested it heavily and the only thing that isn't working is K20 in 'Data Entry' isn't transposing to the 'Results' sheet. It should be appearing in column BG. Any ideas?
 
Upvote 0
K20 in 'Data Entry' isn't transposing to the 'Results' sheet. It should be appearing in column BG. Any ideas?
Yes, my mistake, sorry - missed a "+1" :oops:
Rich (BB code):
rngFound.Offset(, 2).Resize(, UBound(Results) + 1).Value = Results
 
Upvote 0
That's perfect! Thanks again so much, and thanks for the advice with providing data for future posts.
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,678
Members
449,116
Latest member
HypnoFant

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