Creating formula within For and Next

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,404
Office Version
  1. 2016
Platform
  1. Windows
I've got this which updates a cell with a formula;

Code:
If Not IsEmpty(Range("A8").Value) Then
Range("D8").Formula = "=A8 & "" "" & C8 & "" "" & B8"

This code is repeated through to A31 resulting in a lot of code and I'm trying to create a more efficient method of doing this, so have thought about using a For Loop but don't know how the formula would look.

I know how to do this part;

Code:
For i = 8 To 31
If Not IsEmpty(Range("A" & i).Value) Then

but don't know how the 'i' part would be written in the next part;

Code:
Range("D8").Formula = "=A8 & "" "" & C8 & "" "" & B8"

It's probably very straightforward, but only if you know how to do it!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Code:
Range("D" & I).Formula = "=A" & I & "" "" & C" & I & "" "" & B" & I
 
Last edited:
Upvote 0
Thanks,

That doesn't work though - I'm getting an error 'Expected end of statement' and the part that is highlighted is the double speech marks before '& C'.
 
Upvote 0
It might be easier to switch to R1C1 style and use..

Code:
Range("D" & i).FormulaR1C1 = "=RC[-3]&"" ""&RC[-1]&"" ""&RC[-2]"

But if you really wanted to stick with A1 style..

Code:
Range("D" & i).Formula = "=A" & i & "&"" ""&C" & i & "&"" ""&B" & I
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,243
Members
449,075
Latest member
staticfluids

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