Nested If in VBA Macro

manoj_arsul

Board Regular
Joined
Jun 27, 2018
Messages
61
Hi

Could you please help me to fix the below formula in column and its drop down (by increase cell count) till the last row in the VBA Macro

=IF(C2<2,"0-1 Days",IF(C2<3,"1-2 Days",IF(C2<4,"2-3 Days",IF(C2<6,"3-5 Days",">5 Days"))))

at the drop downing Column C has to increase C2,C3,C4....C10

A B C D
=IF(C2<2,"0-1 Days",IF(C2<3,"1-2 Days",IF(C2<4,"2-3 Days",IF(C2<6,"3-5 Days",">5 Days"))))
=IF(C3<2,"0-1 Days",IF(C3<3,"1-2 Days",IF(C3<4,"2-3 Days",IF(C3<6,"3-5 Days",">5 Days"))))
=IF(C4<2,"0-1 Days",IF(C4<,3"1-2 Days",IF(C4<4,"2-3 Days",IF(C4<6,"3-5 Days",">5 Days"))))


Thanks
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
You haven't said how we can determine what the "last row" is so I have assumed that we can tell that from column A. If that is not the case, change the red A in the code to another column that can be used to determine the last row (perhaps column C?)

Rich (BB code):
Sub Insert_Formula()
  Range("D2:D" & Range("A" & Rows.Count).End(xlUp).Row).Formula = "=IF(C2<2,""0-1 Days"",IF(C2<3,""1-2 Days"",IF(C2<4,""2-3 Days"",IF(C2<6,""3-5 Days"","">5 Days""))))"
End Sub

If this is what you meant then also note that you should be able to use this shorter formula instead (if you want)

Rich (BB code):
Range("D2:D" & Range("A" & Rows.Count).End(xlUp).Row).Formula = "=LOOKUP(C2,{0,2,3,5,6},{""0-1"",""1-2"",""2-3"",""3-5"","">5""})&"" Days"""
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,141
Members
453,021
Latest member
Justyna P

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