VBA Concatenate Issue

Roballistic

New Member
Joined
Jan 14, 2021
Messages
11
Office Version
  1. 365
Platform
  1. Windows
I'm not understanding why the code below will generate a #REF! error on the last cell identified to be concatenated (Row 3: Minnie Mouse), yet when I go into where the formula is copied, and I physically replace it with the cell I reference, it gets me exactly what I want (Row 2: Mickey Mouse).

Sheets("Temp2").Select
Columns("A:A").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A1").Select
ActiveCell.FormulaR1C1 = "Index_LN_FN_SSN"
Range("A2").Select

'=CONCAT(B2,R2:S2,O2)
ActiveCell.FormulaR1C1 = "=CONCAT(RC[1],RC[17],RC[18],RC[14])"
Range("A2").Select
Selection.Copy
Range("A2:A501").Select
ActiveSheet.Paste

1st Image is when I took the error from when the code was run and changed to Cell O2


1696286651430.png
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Try Filldown...

UNTESTED CODE- Try this on a COPY of your workbook.
VBA Code:
Sub ConcatenateColumnsOptimized()
    Dim ws As Worksheet
    
    Set ws = ThisWorkbook.Sheets("Temp2")
    ws.Columns("A:A").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    ws.Range("A1").Value = "Index_LN_FN_SSN"
    ws.Range("A2").FormulaR1C1 = "=CONCAT(RC[1],RC[17],RC[18],RC[14])"
    
    ' Fill down the formula from cell A2 to cell A501
    ws.Range("A2:A501").FillDown
End Sub
 
Upvote 0
Solution
Try Filldown...

UNTESTED CODE- Try this on a COPY of your workbook.
VBA Code:
Sub ConcatenateColumnsOptimized()
    Dim ws As Worksheet
   
    Set ws = ThisWorkbook.Sheets("Temp2")
    ws.Columns("A:A").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    ws.Range("A1").Value = "Index_LN_FN_SSN"
    ws.Range("A2").FormulaR1C1 = "=CONCAT(RC[1],RC[17],RC[18],RC[14])"
   
    ' Fill down the formula from cell A2 to cell A501
    ws.Range("A2:A501").FillDown
End Sub
You can consider this now tested code as it worked as you coded above! Thanks for your help!
 
Upvote 0

Forum statistics

Threads
1,215,097
Messages
6,123,076
Members
449,094
Latest member
mystic19

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