# Combine lines of code

#### FROGGER24

##### Well-known Member
Can these lines of code be consolidated into 1 or 2 lines of code

<
Range("I1:I" & Cells(Rows.Count, 2).End(xlUp).Row).FormulaR1C1 = "=(RC[-8]+RC[-7])"
Range("J1:J" & Cells(Rows.Count, 2).End(xlUp).Row).FormulaR1C1 = "=(RC[-7]+RC[-6])"
Range("K1:K" & Cells(Rows.Count, 2).End(xlUp).Row).FormulaR1C1 = "=(RC[-6]+RC[-5])"
Range("L1:L" & Cells(Rows.Count, 2).End(xlUp).Row).FormulaR1C1 = "=(RC[-5]+RC[-4])"
Range("M1:M" & Cells(Rows.Count, 2).End(xlUp).Row).FormulaR1C1 = "=(RC[-4]+RC[-3])"
Range("N1:N" & Cells(Rows.Count, 2).End(xlUp).Row).FormulaR1C1 = "=(RC[-3]+RC[-2])"
>

### Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi - it's not quite 2 lines but my suggestion is:

Code:
``````Sub test()

numCols = 6

For iter = 1 To numCols
Range("I1").Offset(0, iter - 1).FormulaR1C1 = "=(RC[" & (-9 + iter) & "]+RC[" & (-8 + iter) & "])"
Next iter

Range("I1").Resize(Range("B:B").SpecialCells(xlCellTypeLastCell).Row, numCols).FillDown

End Sub``````

Dean, thank for your formula. What I need to do is combine 2 columns into one,(Containing Date & time). So when the code has ran the outputs would only occupy 3 columns (I,J,K)

Would a CONCATENATE work in this case?, can you show a sample of what is in the cells you want to combine and what would you like the final result to look like, such as spaces or other symbols involved, I will leave the formula to Dean.

A data sample would be helpful here just to be clear what you need to do.

Concatenate function would work fine as well as using the '&' operator.

Replies
3
Views
170
Replies
4
Views
419
Replies
16
Views
324
Replies
2
Views
102
Replies
16
Views
465

1,196,513
Messages
6,015,631
Members
441,912
Latest member
Rayna_rahman00

### 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.

### Which adblocker are you using?

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

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