Skip to main content
fixed formatting, "aerated" the post to make easier to read
Source Link

Some tips I suggest trying... VarM

VarM and aa shouldn’t be variants. I would change those to integers.

Overly abundant on counting loops, in this scenario you should loop a range through a named range. 

Also use the .offset(1,0).offset(1,0) instead of adding 1 for rw. Use .offset(0,1).offset(0,1) instead of reading the cells(lastrow,”b”)cells(lastrow,”b”). Set application.calculationapplication.calculation back to automatic at the end (I wouldn’t turn it off but depends on your data rows). Use with end with statements, it’ll help make the code more readable as well. 

You have a lot of if else end if blocks. I would break that into a select case statement when a criteria is met for your formulas. I’m on my phone but I hope this makes enough sense for you to try. This is what the structure would look similar to:

with ws for each cell in MyRNG

‘Select case for cell criteria ‘if statement here for formula criteria ‘End if ‘Next case statement here...

Next cell End with

with ws 
for each cell in MyRNG

‘Select case for cell criteria 
‘if statement here for formula criteria
‘End if
‘Next case statement here...


Next cell 
End with 

Some tips I suggest trying... VarM and a shouldn’t be variants. I would change those to integers.

Overly abundant on counting loops, in this scenario you should loop a range through a named range. Also use the .offset(1,0) instead of adding 1 for rw. Use .offset(0,1) instead of reading the cells(lastrow,”b”). Set application.calculation back to automatic at the end (I wouldn’t turn it off but depends on your data rows). Use with end with statements, it’ll help make the code more readable as well. You have a lot of if else end if blocks. I would break that into a select case statement when a criteria is met for your formulas. I’m on my phone but I hope this makes enough sense for you to try. This is what the structure would look similar to:

with ws for each cell in MyRNG

‘Select case for cell criteria ‘if statement here for formula criteria ‘End if ‘Next case statement here...

Next cell End with

Some tips I suggest trying...

VarM and a shouldn’t be variants. I would change those to integers.

Overly abundant on counting loops, in this scenario you should loop a range through a named range. 

Also use the .offset(1,0) instead of adding 1 for rw. Use .offset(0,1) instead of reading the cells(lastrow,”b”). Set application.calculation back to automatic at the end (I wouldn’t turn it off but depends on your data rows). Use with end with statements, it’ll help make the code more readable as well. 

You have a lot of if else end if blocks. I would break that into a select case statement when a criteria is met for your formulas. I’m on my phone but I hope this makes enough sense for you to try. This is what the structure would look similar to:

with ws 
for each cell in MyRNG

‘Select case for cell criteria 
‘if statement here for formula criteria
‘End if
‘Next case statement here...


Next cell 
End with 
Source Link

Some tips I suggest trying... VarM and a shouldn’t be variants. I would change those to integers.

Overly abundant on counting loops, in this scenario you should loop a range through a named range. Also use the .offset(1,0) instead of adding 1 for rw. Use .offset(0,1) instead of reading the cells(lastrow,”b”). Set application.calculation back to automatic at the end (I wouldn’t turn it off but depends on your data rows). Use with end with statements, it’ll help make the code more readable as well. You have a lot of if else end if blocks. I would break that into a select case statement when a criteria is met for your formulas. I’m on my phone but I hope this makes enough sense for you to try. This is what the structure would look similar to:

with ws for each cell in MyRNG

‘Select case for cell criteria ‘if statement here for formula criteria ‘End if ‘Next case statement here...

Next cell End with