VBA Help - Code that will update a value with the header name

Johnny Thunder

Well-known Member
Joined
Apr 9, 2010
Messages
693
Office Version
  1. 2016
Platform
  1. MacOS
Hello all,

I have a small grid of data that has dollar amounts in the data, I am trying to have a macro loop thru each column A:F and look at all rows of data in each column and replace any values with the header name. See my example of the Grid below. The code will need to ignore blank cells and move on to the next. The Column A can be used to determine the last row with data. Of course this is a small sample of what I need but I should be able to make any changes to make it scale for my actual data set.

Any help is appreciated. Thanks! ?

Original Data

_____xl2bb.xlam
ABCDEF
1YellowBlueBlackRedPurple
2Map 11500300060001200024000
3Map 230006000120002400048000
4Map 3200350
5Map 425005000100002000040000
Sheet2



Desired result

_____xl2bb.xlam
ABCDEF
8YellowBlueBlackRedPurple
9Map 1YellowBlueBlackRedPurple
10Map 2YellowBlueBlackRedPurple
11Map 3BlueRed
12Map 4YellowBlueBlackRedPurple
Sheet2
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Is you data in B:F hard values or formulae?
 
Upvote 0
OK, how about
VBA Code:
Sub JohnnyThunder()
   With Range("B2:F" & Range("A" & Rows.Count).End(xlUp).Row)
      .SpecialCells(xlConstants).FormulaR1C1 = "=r1c"
      .Value = .Value
   End With
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,734
Messages
6,126,542
Members
449,316
Latest member
sravya

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