Excel formula to VBA code

kc999

New Member
Joined
Jun 17, 2014
Messages
3
I am trying to understand how to write the following code in VBA rather than use the following formula which does work.

Column A formula:
=IF(AND(F2="Red\Recurring",B2="No"),"delete row",IF(AND(F2="Blue\Recurring",B2="No"),"delete row",IF(AND(F2="Yellow\Recurring",B2="No"),"delete row","ok")))

Column B is a formula too, which I am sure could become part of a more complicated piece of VBA code.
=IF(AND($E2="Yellow",$K2="orange)"),"Important",IF(AND($E2="Blue",$K2=""),"Important",IF(AND($E2="Red",$K2=""),"Important","No")))


The table I am using looks like this.
[TABLE="width: 1397"]
<tbody>[TR]
[TD]Keep[/TD]
[TD]Important[/TD]
[TD]Workstream[/TD]
[TD]Customer[/TD]
[TD]Team[/TD]
[TD]Path[/TD]
[/TR]
[TR]
[TD]ok[/TD]
[TD]Important[/TD]
[TD]Red[/TD]
[TD]Sales and Trade Systems[/TD]
[TD]Red[/TD]
[TD]Red\Recurring[/TD]
[/TR]
[TR]
[TD]ok[/TD]
[TD]No[/TD]
[TD]Integration Account Planning[/TD]
[TD]Promo list[/TD]
[TD]Integration Account Planning[/TD]
[TD]Integration Account Planning\Iteration 13[/TD]
[/TR]
[TR]
[TD]ok[/TD]
[TD]Important[/TD]
[TD]Red[/TD]
[TD]Enterprise Warehousing[/TD]
[TD]Red[/TD]
[TD]Red\Recurring[/TD]
[/TR]
[TR]
[TD]ok[/TD]
[TD]Important[/TD]
[TD]Red[/TD]
[TD]Enterprise Warehousing[/TD]
[TD]Red[/TD]
[TD]Red\Recurring[/TD]
[/TR]
[TR]
[TD]ok[/TD]
[TD]Important[/TD]
[TD]Red[/TD]
[TD]Financial Accounting Services[/TD]
[TD]Red[/TD]
[TD]Red\Recurring[/TD]
[/TR]
[TR]
[TD]ok[/TD]
[TD]Important[/TD]
[TD]Red[/TD]
[TD]Sales and Trade Systems[/TD]
[TD]Red[/TD]
[TD]Red\Recurring[/TD]
[/TR]
[TR]
[TD]delete row[/TD]
[TD]No[/TD]
[TD]Integration Integration[/TD]
[TD]Interfaces[/TD]
[TD]Integration[/TD]
[TD]Red\Recurring[/TD]
[/TR]
[TR]
[TD]ok[/TD]
[TD]No[/TD]
[TD]Integration Order to Cash Core[/TD]
[TD]Master Data Gathering[/TD]
[TD]Integration[/TD]
[TD]Integration\Graveyard[/TD]
[/TR]
[TR]
[TD]ok[/TD]
[TD]Important[/TD]
[TD]Red[/TD]
[TD]Customer Order Management[/TD]
[TD]Red[/TD]
[TD]Red\Recurring[/TD]
[/TR]
[TR]
[TD]ok[/TD]
[TD]Important[/TD]
[TD]Red[/TD]
[TD]IT Process Governance[/TD]
[TD]Blue[/TD]
[TD]Blue\Recurring[/TD]
[/TR]
[TR]
[TD]ok[/TD]
[TD]No[/TD]
[TD]Integration Account Planning[/TD]
[TD]Planning UOM[/TD]
[TD]Integration[/TD]
[TD]Integration Account Planning\Iteration 13[/TD]
[/TR]
[TR]
[TD]ok[/TD]
[TD]No[/TD]
[TD]Office 365[/TD]
[TD]Site Owner Training (Admin Topics)[/TD]
[TD]Office 365\SharePoint - Online[/TD]
[TD]Office 365\Iteration 2[/TD]
[/TR]
[TR]
[TD]ok[/TD]
[TD]No[/TD]
[TD]Interim Reporting Database[/TD]
[TD]SKU: Leading zeros causing SKU to exist in multiple formats[/TD]
[TD]Interim Reporting Database\Master Data[/TD]
[TD]Interim Reporting Database\Iteration 9[/TD]
[/TR]
[TR]
[TD]ok[/TD]
[TD]Important[/TD]
[TD]Blue[/TD]
[TD]Applications[/TD]
[TD]Blue[/TD]
[TD]Blue\Recurring[/TD]
[/TR]
[TR]
[TD]delete row[/TD]
[TD]No[/TD]
[TD]Yellow[/TD]
[TD]AP & Treasury[/TD]
[TD]Yellow[/TD]
[TD]Yellow\Recurring[/TD]
[/TR]
[TR]
[TD]ok[/TD]
[TD]Important[/TD]
[TD]Prep[/TD]
[TD]Cutover/Testing/Secuirty[/TD]
[TD]Red[/TD]
[TD]Prep\Iteration 11

[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
This works in the scenario you presented
Code:
Option Explicit


Sub kc()
Dim lr As Long
lr = Range("C" & Rows.Count).End(xlUp).Row
Dim i As Long


Application.ScreenUpdating = False
For i = 2 To lr
Range("A" & i).FormulaR1C1 = "=IF(AND(RC[5]=""Red\Recurring"",RC[1]=""No""),""delete row"",IF(AND(RC[5]=""Blue\Recurring"",RC[1]=""No""),""delete row"",IF(AND(RC[5]=""Yellow\Recurring"",RC[1]=""No""),""delete row"",""ok"")))"
Range("B" & i).FormulaR1C1 = "=IF(AND(RC5=""Yellow"",RC11=""orange""),""Important"",IF(AND(RC5=""Blue"",RC11=""""),""Important"",IF(AND(RC5=""Red"",RC11=""""),""Important"",""No"")))"
Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thanks for the quick reply. I can get that to do the evaluations, but it does not delete the rows based on formula A. That's my ultimate goal.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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