Combine lines of code

FROGGER24

Well-known Member
Joined
May 22, 2004
Messages
704
Office Version
  1. 2013
  2. 2010
Platform
  1. Windows
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
 
Upvote 0
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)
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0

Forum statistics

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