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
 

Some videos you may like

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
10,171
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
 

Etablir

New Member
Joined
Jan 22, 2014
Messages
2
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,330
Messages
5,601,000
Members
414,419
Latest member
JRDunya

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
Top