Replace contents of cell with adjacent cell based on certain text

mozza90

New Member
Joined
Mar 19, 2015
Messages
32
Hi,

I have a sheet which lists data like the below:

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD="align: center"]Column E[/TD]
[TD="align: center"]Column F[/TD]
[/TR]
[TR]
[TD]Apple[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Banana[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Other[/TD]
[TD]Melon[/TD]
[/TR]
[TR]
[TD]Other[/TD]
[TD]Lime[/TD]
[/TR]
[TR]
[TD]Banana[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


If column E contains "Other" then the answer is found in column F. What's the best way to look down column E, find "Other", and replace other with the contents of the adjacent cell e.g. Other becomes Melon, and the second instance of Other becomes Lime?
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
With VBA code, like this:
Code:
Sub MyReplace()

    Dim lastRow As Long
    Dim cell As Range
    
    Application.ScreenUpdating = False
    
'   Find last row with data in column E
    lastRow = Cells(Rows.Count, "E").End(xlUp).Row
    
'   Loop through column E
    For Each cell In Range("E1:E" & lastRow)
        If cell = "Other" Then
            cell = cell.Offset(0, 1)
        End If
    Next cell
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Use a spare column and enter formula:
Code:
=IF(E2="Other",F2,E2)
Drag that formula down to the last row, then copy and paste values to your destination cell, then delete the spare column
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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