Solved

Excel VBA Amendment

Posted on 2011-03-01
11
168 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
Comment Utility
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
Comment Utility
Note: The solution I provided is if you want to apply to both columns (Q and L).
0
 

Author Comment

by:cpatte7372
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 26

Expert Comment

by:redmondb
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Hi Brian,

Its ok. I figured it out..

Cheers
0
 

Author Closing Comment

by:cpatte7372
Comment Utility
Cheers mate.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
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.

772 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

11 Experts available now in Live!

Get 1:1 Help Now