Copy value from other row into same column

most

Board Regular
Joined
Feb 22, 2011
Messages
106
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
  2. Mobile
Hello,
I need help with solving this issue, I want to find and fill data from another row and paste into same column.
I thought VLOOKUP could solve it, but it only works "down", not "up".

Orginal data looks like these
IDGrade
123456
123456Y_15
654321Y_16
654321

<tbody>
</tbody>

With
Code:
=VLOOKUP(A2;A:B;2;FALSE)
I get these results.
But expected result is that line 1 should have Y_15.

IDGrade
1234560
123456Y_15
654321Y_16
654321Y_16

<tbody>
</tbody>
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Your example data suggests there will only ever be one "non-zero value" for each ID ???

If so,

in C2
=LOOKUP(2,1/((A$2:A$5=A2)*(B$2:B$5<>"")),B$2:B$5)
and copy down the column
 
Last edited:
Upvote 0
Your example data suggests there will only ever be one "non-zero value" for each ID ???

If so,

in C2
=LOOKUP(2,1/((A$2:A$5=A2)*(B$2:B$5<>"")),B$2:B$5)
and copy down the column

Nope, I didn't get it to work, unsure why.
But I managed to solve it with this VBA. (observe that columnref is diffrent from example above)
Code:
For Each c In Range(Cells(7, 9), Cells(LastRow, 9))  If c.Value = "" Then
     Set foundRng = Range("B7:B" & LastRow).Find(c.Offset(0, -7).Value)
     If Not foundRng Is Nothing Then
       If foundRng.Offset(0, 7).Value = "" Then
        Set foundRng2 = Range("B" & foundRng.Row & ":B" & LastRow).Find(c.Offset(0, -7).Value)
        c.Value = foundRng2.Offset(0, 7).Value
       Else
        c.Value = foundRng.Offset(0, 7).Value
       End If
     End If
  End If
Next c
 
Upvote 0
Need to bump this up, realized that my code doesn't work.
My code finds the value when it goes "down"(line 13), but not "up"(line 8).
Any one have a suggestion what is wrong? I can't see it...

Excel 2016 (Windows) 32 bit
A
B
C
D
E
F
G
H
I
1
2
3
4
5
6
IDGrade
7
126302​
Y_10
8
126302​
9
126301​
Y_10
10
126301​
Y_10
11
126300​
Y_10
12
126300​
Y_10
13
126299​
14
126299​
Y_11
Sheet: Sheet1


Code:
Sub TEST()
LastRow = 14
'Find Grade
For Each c In Range(Cells(7, 9), Cells(LastRow, 9))
  If c.Value = "" Then
     Set foundRng = Range("B7:B" & LastRow).Find(c.Offset(0, -7).Value)
     If Not foundRng Is Nothing Then
       If foundRng.Offset(0, 7).Value = "" Then
        Set foundRng2 = Range("B" & foundRng.Row & ":B" & LastRow).Find(c.Offset(0, -7).Value)
        c.Value = foundRng2.Offset(0, 7).Value
       Else
        c.Value = foundRng2.Offset(0, 7).Value
       End If
     End If
  End If
Next c
End Sub
 
Last edited:
Upvote 0
Nope, I didn't get it to work, unsure why.[?QUOTE]

My solution works fine.
Copy and paste your example data into a blank sheet
So Grade is in B1

in C2
=LOOKUP(2,1/((A$2:A$5=A2)*(B$2:B$5<>"")),B$2:B$5)
copy down the column

Column C are your results and each row has a value dependant on the ID
 
Upvote 0
Okej, I got your code to work now. Problem was that I running it in 'column I' which I guess creates some kind of circular reference.
I solved it by running the lookup in column A and then copy the data to column I, in my original data I need to run it for two columns and about 11000 lines, so it's not very neat or fast but it solved the problem! Thanks for you assistance.
 
Upvote 0
Well yep, if you dont specify any row/column or cell references I have to assume the top left hand cell is A1.
I can't produce a formula that looks at a specific part of a spreadsheet without mentioning cell references.
Once the formula works it's then over to you to adjust to formula accordingly to reflect your actual sheet.
 
Upvote 0

Forum statistics

Threads
1,214,878
Messages
6,122,062
Members
449,064
Latest member
scottdog129

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