Solved

Excel VBA Amendment

Posted on 2011-03-01
11
172 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 
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
 
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

790 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