[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Excel VBA Amendment

Posted on 2011-03-01
11
Medium Priority
?
177 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 33

Accepted Solution

by:
jppinto earned 2000 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
 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

656 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