How To Concatenate Data On Static Columns on Dynamic Cell?

Etablir

New Member
Joined
Jan 22, 2014
Messages
2
My data that I receive are dynamic in the sense that the row count and column count are everchanging, but the columns that I am trying to concatenate will always be in column J and K. I want to put the concatenation at the end of the row to the right and then autofill it. So if I have an array up to column JT, I want the concatenation of J2&K2 at JU2 and then autofilled.

What I've tried to attempt is the following with the error "Run-time error '1004': Application-defined or object -defined error" on the bolded.

Also I have tried to look up on how to autofill this given formula but I can only dynamically reference the row but not the column. Because, like I said the column is also dynamic so the formula might not always be on column JU.


Sub Macro1()
'
Macro1 Macro
'
Dim lastrow As Long
lastrow = Range("A" & Rows.Count).End(xlUp).Row

Dim lastCol As Long
lastCol = Sheet1.Cells(1, Columns.Count).End(xlToLeft).Column

Dim ColK As Integer
ColK = lastCol - 10

Dim ColJ As Integer
ColJ = lastCol - 11



Selection.End(xlToRight).Select
ActiveCell.Offset(rowOffset:=0, columnOffset:=1).Select
ActiveCell.FormulaR1C1 = "*"
ActiveCell.Offset(rowOffset:=0, columnOffset:=1).Select
ActiveCell.FormulaR1C1 = "Combined USI"
ActiveCell.Offset(rowOffset:=0, columnOffset:=1).Select
ActiveCell.FormulaR1C1 = "In Position Report?"
ActiveCell.Offset(rowOffset:=1, columnOffset:=-2).Select
ActiveCell.FormulaR1C1 = "*"
ActiveCell.Offset(rowOffset:=0, columnOffset:=1).Select
ActiveCell.FormulaR1C1 = "=RC[-ColK]&RC[-ColJ]"
ActiveCell.AutoFill Destination:=Range("JU2:JW" & lastrow)

'
End Sub
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Try:
Code:
Sub ConCatCells()
    Application.ScreenUpdating = False
    Dim LastRow As Long
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Dim lCol As Long
    Dim rng As Range
    For Each rng In Range("J2:J" & LastRow)
        lCol = Range("IV" & rng.Row).End(xlToLeft).Column
        Cells(rng.Row, lCol + 1) = rng & rng.Offset(0, 1)
    Next rng
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thank you for the help Mumps but unfortunately it did not work. Perhaps I may have been implementing it incorrectly.
I have figured it out myself.

All I want to do is:

RC[-ColK] to equal RC [-270]
RC[-ColJ] to equal RC [-269]
If Column.count also known as Lis 280

In other words, I needed RC[-ColK] to recognize me to tell it RC[-270]. To do so I just used ActiveCell.FormulaR1C1 = "=RC[" & -ColK & "]&RC[" & -ColJ & "]" in place.
 
Upvote 0

Forum statistics

Threads
1,213,521
Messages
6,114,104
Members
448,548
Latest member
harryls

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