Link to home
Start Free TrialLog in
Avatar of cpatte7372
cpatte7372Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Excel VBA Amendment

Hello Experts,

An expert compiled some code for me that is working very. It basically alerts me when a certain condition is met.

The code is as follows:


For Each xCell In Range("q2:q" & xLastRow)
    xValue = xCell.Value
    xValue2 = xCell.Offset(0, -13).Value
    If Not IsError(xValue) And Not IsError(xValue2) Then
        If xValue <> "" And xValue2 <> "" And Round(xValue, 2) = Round(xValue2, 2) Then
            PlayTheSound "Windows XP Ringin.wav"

            Cells(1, 17).Interior.Color = 255
            Exit Sub
        End If
    End If
Next

Cells(1, 17).Interior.Color = 65535

As you can see the code is applied to column Q.

Can someone please show me how to apply the same code to column L

I tried it myself but failed.

Cheers


Trade-Day--10-Experts-1-.xlsm
Avatar of jppinto
jppinto
Flag of Portugal image

Just change this line:

For Each xCell In Range("q2:q" & xLastRow)

For this:

For Each xCell In Range("q2:q" & xLastRow,"L2:L" & xLastRow)

jppinto
Note: The solution I provided is if you want to apply to both columns (Q and L).
Avatar of cpatte7372

ASKER

Thanks for responding mate..

Yes, I do. But what if I want a different sound for L?

ASKER CERTIFIED SOLUTION
Avatar of jppinto
jppinto
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
jppinto,

Do you mean:

For Each xCell In Range("l2:l" & xLastRow)
    xValue = xCell.Value
    xValue2 = xCell.Offset(0, -8).Value
    If Not IsError(xValue) And Not IsError(xValue2) Then
        If xValue <> "" And xValue2 <> "" And Round(xValue, 2) = Round(xValue2, 2) Then
            PlayTheSound "Windows XP Exclamation.wav"

            Cells(1, 17).Interior.Color = 255
            Exit Sub
        End If
    End If
Next

Because that didn't work
Avatar of redmondb
cpatte7372,

If you're using Trade-Day-sample_V2.xlsm, please note that the Worksheet_Calculate macro has been disabled (by renaming it to xWorksheet_Calculate).

Cheers,
Brian.
Brian,

Thanks for that.

All I need is to have the alerts that you kindly helped me with applied to column L in the attached spreadsheet.

Cheers
cpatte7372,

I'm not sure what you currently have, but I suspect the problem is the "Exit Sub" in the For loop for column Q. That was OK in the original macro as there was no further processing, but you've possibly now added column L's code after this and it's not being reached.

Sorry, I'm heading off now, but it's very straightforward and I'm sure jppinto will sort it for you.

Cheers,
Brian.
Hi Brian,

Its ok. I figured it out..

Cheers
Cheers mate.