How can I replace each x in a column with its column header?

Monsignor

Board Regular
Joined
May 30, 2011
Messages
162
Starting with a table like this:

NAMEIllinoisTorontoMoscowBelize
Sarahx
Robertoxxx
Karenxx
Olivia
Toddxx

<tbody>
</tbody>



The desired result is:

NAMEIllinoisTorontoMoscowBelize
SarahIllinois
RobertoTorontoMoscowBelize
KarenIllinoisMoscow
Olivia
ToddMoscowBelize

<tbody>
</tbody>


I've unpivoted, outer joined, added index columns, replaced values and found several messy ways to get a result. The problems are with:
- Someone who doesn't have an x will disappear. Like Olivia in my example.
- Adding a new City column doesn't show up with "refresh"

Any help is greatly appreciated!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
If you want a Vba solution you can try this:
Code:
Sub City_Names()
'Modified 1-27-18 3:00 PM EST
Application.ScreenUpdating = False
Dim c As Range
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
    For Each c In Range("A2:E" & Lastrow)
        If c.Value = "x" Then c.Value = Cells(1, c.Column).Value
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,388
Messages
6,119,227
Members
448,878
Latest member
Da9l87

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