Extract Values From Cells Based On Corresponding Cell Value

fiberboysa

Board Regular
Joined
Apr 25, 2012
Messages
106
Office Version
  1. 365
Platform
  1. Windows
Hi Dear Allz,
I am trying to extract values from preceding rows based on a value which is given in next columns.

Like in following example, in cell A2 Cell value is 10 (Highlighted in Green) the corresponding value in cell D2 is 3 (Highlighted in Red) so the value required in Cell E2 is combination of following three rows of Cell A2 i.e. values of cells A3, A4 and A5 which are A-1111 B-2222 C-3333 respectively. And in case of Cell A6 the corresponding value in cell D6 is 2 so the required value in cell E6 will be D-4444 E-5555.

The data continuous like this and formula or VBA code will fill my requirement in column E. Kindly let me know if you need further clarification. Thanks in advance... :)

ABCDE
1CLMN 1CLMN 2CLMN 3CLMN 4CLMN 5 (Required Formula/VBA)
2103A-1111 B-2222 C-3333
3A-1111
4B-2222
5C-3333
62024444 5555
74444
85555
9304
10F-6666F-6666 7777 H-8888 9999
117777
12H-8888
139999

<tbody>
</tbody>
 
You're welcome & thanks for the feedback
 
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Dear Fluff,
There is one more request...
What if I want SLR# in the next line instead of seprated by a space? Like this...

ABCDE
1CLMN 1CLMN 2CLMN 3CLMN 4CLMN 5 (Required Formula/VBA)
2103A-1111
3SLR# A-1111B-2222
4SLR# B-2222C-3333
5SLR# C-3333
62024444
7SLR# 44445555
8SLR# 5555
9304
10SLR# F-6666F-6666
11SLR# 77777777
12H-8888
13SLR# H-88889999
14ABCXYZ 12
15SLR# 9999

<tbody>
</tbody>

I have tried the following but its not working...

Code:
Function fiberboysa(Rng As Range, Rws As Long) As String
   Dim i As Long
   Dim Cl As Range
   
   For Each Cl In Rng
      If Left(Cl, 4) = "SLR#" Then
         fiberboysa = fiberboysa & Cl.Value
         ActiveCell.Offset(1, 0).Select
         i = i + 1
         If i = Rws Then Exit For
      End If
   Next Cl
   fiberboysa = Trim(Replace(fiberboysa, "SLR#", ""))
End Function

Code:
Function fiberboysa(Rng As Range, Rws As Long) As String
Dim i As Long
Dim Cl As Range

For Each Cl In Rng
If Left(Cl, 4) = "SLR#" Then
fiberboysa = fiberboysa & Cl.Value
Application.SendKeys "{ENTER}"
i = i + 1
If i = Rws Then Exit For
End If
Next Cl
fiberboysa = Trim(Replace(fiberboysa, "SLR#", ""))
End Function
 
Upvote 0
You would be better of with a formula for that.
As that is beyond my knowledge of formulae, you had better start a new thread.
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,934
Members
449,094
Latest member
teemeren

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