concatenate using set "search column for text" range & corresponding row - VBA Excel

minddumps

New Member
Joined
Jun 29, 2011
Messages
16
Hello All,

I am receiving incorrect data with this piece of my VBA.

Code:
            Set rngRankHeader = Range("A1:ZZ1").Find(What:="Rank", LookAt:=xlPart, _
                    MatchCase:=False, SearchFormat:=False) 'Find Rank Header 'LookIn:=xlValues,
                        
                        If rngRankHeader Is Nothing Then
                        MsgBox "A column with the header 'Rank' was not found; recheck your column names to ensure the 'Rank' column does have the header 'Rank'.", vbExclamation
                        Exit Sub
                        End If
                        
            LR = Cells(Rows.Count, rngNameHeader.Offset(, -4).Column).End(xlUp).Row 'I need to concatenate existing Column Header Row "Rank", Column Header "First Name", "MI", "Last Name";
            rngNameHeader.Offset(1, 3).Resize(LR - 1).FormulaR1C1 = _
            "=CONCATENATE(" & Cells(2, rngRankHeader.Column).Address(0, 0) & ","" "",RC[-2],"" "",RC[-1],"" "",RC[-3])" '********************************This will follow code from above; Select same column with formuals to paste values section"
                
            rngNameHeader.Offset(, 3).EntireColumn.Select
            Selection.Replace What:="'", Replacement:="", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False

The piece that's incorrect is
Code:
"& Cells(2,  rngRankHeader.Column).Address(0, 0) &
because it is returning a particular cell's data in the selected column and repeating it throughout every row vs giving me the column's cell's data within the corresponding row. I also tried using
Code:
& rngRankHeader.Address(1, 1, xlR2C1) &
and that didn't work either.

For example:
[TABLE="width: 500"]
<tbody>[TR]
[TD]abc[/TD]
[TD]def[/TD]
[TD]=abcdef (as it should)
[/TD]
[/TR]
[TR]
[TD]abc[/TD]
[TD]ghi[/TD]
[TD]=abcdef (pulling from 1st cell instead of ghi)
[/TD]
[/TR]
[TR]
[TD]abc[/TD]
[TD]jkl[/TD]
[TD]=abcdef (pulling from 1st cell instead of jkl)
[/TD]
[/TR]
</tbody>[/TABLE]


Is anyone able to correct this for me?
 
Last edited:

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.

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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