Need Help with a formula in VBA?

ucsutah1

Board Regular
Joined
Jan 17, 2011
Messages
56
Hi,

This is the last piece of code that I need to make this project work. Please, Please can someone help? I have been working on this entire code project for about a month now and just need this to complete it. I need this in VBA. This is a sample of the worksheet i am working on. [FONT=source_sans_proregular]https://mega.nz/#!2g91xI7T!YacS-ADfPKqxfhbqpS5BGYMdXt8HOUEQh-yxq_cRoHM[/FONT]

If Column I is higher than Column J then copy Column I to Column AD and highlight entire cell to red.

If Column I is lower than Column J then lower by 5% only if Column J is within 10% of Column I. Then Output to Column AD and highlight entire cell to yellow.

If any of the arguments above are not met then keep same value and copy from column J to column AD and don't highlight the cell.

thanks
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
If you want it to run the code just on the active row (ie. click any cell in the target row then click a button to run the macro) then try the code below. If you want it to loop through the data and process all in one go, let me know. Sorry the code tags are acting strangely, so I'll just have to dump it below without notes, it fairly straightforward and easy to follow though:

<j and="" j="" is="" within="" 10%="" of="" i="" then...
<j and="" j="" is="" within="" 10%="" of="" i="" then...

Sub ProcessSelected()


Dim Ival As Long
Ival = ActiveSheet.Range("I" & ActiveCell.Row).Value
Dim Jval As Long
Jval = ActiveSheet.Range("J" & ActiveCell.Row).Value


If Ival > Jval Then
Range("AD" & ActiveCell.Row).Value = Ival
Range("AD" & ActiveCell.Row).Interior.Color = RGB(250, 0, 0)
ElseIf Ival < Jval And Jval <= (Ival + (Ival * 0.1)) Then
Range("I" & ActiveCell.Row).Value = Ival - (Ival * 0.05)
Range("AD" & ActiveCell.Row).Value = Range("I" & ActiveCell.Row).Value
Range("AD" & ActiveCell.Row).Interior.Color = RGB(250, 250, 0)
Else
Range("AD" & ActiveCell.Row).Value = Jval
End If




End Sub
</j></j>
 
Last edited:
Upvote 0
Hi,

thanks for getting back to me, yes i would like it to loop through the data and process all in one go.

Also, is there a way that I could grab all the rows in column ad that have red or yellow and copy them with column b to a new worksheet?

thanks
 
Last edited:
Upvote 0
HI MisterProzilla,

Yes, I would like to loop through the data and process all in one go.

Also, is there a way that I could grab all the rows in column ad that have red or yellow and copy them with column b to a new worksheet?

thanks
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,310
Members
452,634
Latest member
cpostell

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