What is wrong with my formula code

floridagunner

Board Regular
Joined
Jul 20, 2007
Messages
60
Hello all,

I'm using the following code to enter a formula into column B which references values in column T:


Code:
'Populate Program name column with formulas now referencing values in column-T.

Dim ab As Long, c As Long
ab = Cells(Rows.Count, "T").End(xlUp).Row
For c = 2 To ab
Range("B" & c).Formula = "=IF(LEFT(T" & c & ",1)=""D"",IF(VALUE(MID(T" & c & ",6,2)) " & _
"<24,""Carbon Abatement"",""EE Reloaded""),""EEE"")"
Next c

The problem is that when Excel gets to processing this section of the code it is taking it approximately 35 minutes to process for about 42,000 rows, which I think is abnormally long.

I want to know if there is a way I can speed this process up. Is there a data type declaration that I should be using? Is long perhaps the wrong data type to be using? Should I be using a different type of code alltogether?

Any help is appreciated.
 

Some videos you may like

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
Try putting the formula in all cells at the same time instead of looping..

Code:
ab = Cells(Rows.Count, "T").End(xlUp).Row
Range("B2:B" & ab).Formula = "=IF(LEFT(T2,1)=""D"",IF(VALUE(MID(T2,6,2)) " & _
"<24,""Carbon Abatement"",""EE Reloaded""),""EEE"")"
 

Watch MrExcel Video

Forum statistics

Threads
1,122,509
Messages
5,596,568
Members
414,079
Latest member
Frills

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