Solved

Excel VBA Amendment

Posted on 2011-03-01
11
169 Views
Last Modified: 2012-06-21
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
0
Comment
Question by:cpatte7372
  • 5
  • 3
  • 2
11 Comments
 
LVL 33

Expert Comment

by:jppinto
ID: 35012027
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
0
 
LVL 33

Expert Comment

by:jppinto
ID: 35012044
Note: The solution I provided is if you want to apply to both columns (Q and L).
0
 

Author Comment

by:cpatte7372
ID: 35012075
Thanks for responding mate..

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

0
 
LVL 33

Accepted Solution

by:
jppinto earned 500 total points
ID: 35012104
Then the easiest way would be to repeat the same block of code and change only the range and the name of the sound file.
0
 

Author Comment

by:cpatte7372
ID: 35012135
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
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 26

Expert Comment

by:redmondb
ID: 35012183
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.
0
 

Author Comment

by:cpatte7372
ID: 35012223
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
0
 
LVL 26

Expert Comment

by:redmondb
ID: 35012354
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.
0
 

Author Comment

by:cpatte7372
ID: 35012518
Hi Brian,

Its ok. I figured it out..

Cheers
0
 

Author Closing Comment

by:cpatte7372
ID: 35498063
Cheers mate.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now