473,379 Members | 1,174 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Target Column & Row question

8
I am trying to have any cell that in any row in any column (based upon code address change) that would Speak a word if the number is Under <10 and play a sound (wav) if the number is over >10.
This code works fine for all of column A, but on column B it uses the Speech and Sound from column C.
Thank you for your help.




Expand|Select|Wrap|Line Numbers
  1. Private Declare Function sndPlaySound Lib "winmm.dll" _
  2. Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
  3. ByVal uFlags As Long) As Long
  4. Private Sub Worksheet_Change(ByVal Target As Excel.Range)
  5.     Dim strSound As String
  6.     Dim strtalk As String
  7.  
  8.     If Not Intersect(Target, Range("$A$1,$A$2,$A$3,$A$4,$A$5,$A$6,$B$2,$C$2")) Is Nothing Then
  9.  
  10.     If Target.Column = 2 Or Target.Column = 3 Then
  11.     strSound = Choose(Target.Row, "Drumroll", "beep")
  12.     strtalk = Choose(Target.Row, "house and horn", "Dog  and  cat")
  13.  
  14.   Else
  15.     strSound = Choose(Target.Row, "tada", "ding", "tada", "beep", "ding", "beep")
  16.     strtalk = Choose(Target.Row, "Dog", "Cat", "Pig", "House", "cat", "Rat")
  17.   End If
  18.  
  19.  
  20.   If Target.Value > 10 Then
  21.     sndPlaySound "C:\WINDOWS\Media\" & strSound, 0
  22.   End If
  23.   If Target.Value < 10 Then
  24.     Application.Speech.Speak strtalk, 0
  25.   End If
  26. End If
  27.  
  28. End Sub
  29.  
Dec 9 '06 #1
15 10817
Killer42
8,435 Expert 8TB
I am trying to have any cell that in any row in any column (based upon code address change) that would Speak a word if the number is Under <10 and play a sound (wav) if the number is over >10.
This code works fine for all of column A, but on column B it uses the Speech and Sound from column C.
Expand|Select|Wrap|Line Numbers
  1. Private Declare Function sndPlaySound Lib "winmm.dll" _
  2. Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
  3. ByVal uFlags As Long) As Long
  4. Private Sub Worksheet_Change(ByVal Target As Excel.Range)
  5.     Dim strSound As String
  6.     Dim strtalk As String
  7.  
  8.     If Not Intersect(Target, Range("$A$1,$A$2,$A$3,$A$4,$A$5,$A$6,$B$2,$C$2")) Is Nothing Then
  9.       If Target.Column = 2 Or Target.Column = 3 Then
  10.         strSound = Choose(Target.Row, "Drumroll", "beep")
  11.         strtalk = Choose(Target.Row, "house and horn", "Dog  and  cat")
  12.       Else
  13.         strSound = Choose(Target.Row, "tada", "ding", "tada", "beep", "ding", "beep")
  14.         strtalk = Choose(Target.Row, "Dog", "Cat", "Pig", "House", "cat", "Rat")
  15.       End If
  16.       If Target.Value > 10 Then
  17.         sndPlaySound "C:\WINDOWS\Media\" & strSound, 0
  18.       End If
  19.       If Target.Value < 10 Then
  20.         Application.Speech.Speak strtalk, 0
  21.       End If
  22.     End If
  23. End Sub
  24.  
(I've modified the indenting of the code for clarity - at least in I find it clearer, anyway. :))

I'm not familiar with the Intersect function, so may be way off-track here. But surely this line
Expand|Select|Wrap|Line Numbers
  1. If Target.Column = 2 Or Target.Column = 3 Then
instructs the system to treat columns B and C in the same way?
Dec 10 '06 #2
amx
8
(I've modified the indenting of the code for clarity - at least in I find it clearer, anyway. :))

I'm not familiar with the Intersect function, so may be way off-track here. But surely this line
Expand|Select|Wrap|Line Numbers
  1. If Target.Column = 2 Or Target.Column = 3 Then
instructs the system to treat columns B and C in the same way?

Thank you for your help.
Do you have any ideas on how to make this work.
Dec 10 '06 #3
Killer42
8,435 Expert 8TB
Thank you for your help.
Do you have any ideas on how to make this work.
I don't think I understand well enough exactly what is supposed to happen. I mean, I follow the basic if_blah_play_sound_otherwise_speak thing, but not exactly where all this is supposed to happen, and where it isn't.

As I said, I'm not familiar with Intersect( ) but it looks as though you are applying some sort of "business rules" on where you will perform the various actions. Just need some more detail on the rules behind the code.
Dec 11 '06 #4
amx
8
Killer42 - Thank you for your help.
I am just trying to see if I can get this concept to work. I am trying to have any cell or any amount of cells on a worksheet make a "Sound" from the result of a formula is less then 10 (or if any letter "A") or have it speak a word if the same cell has a number from the results of a formula.
This would do the same thing as "Conditional Formatting" does with colors or fonts. This would do it with Wav Sounds and Speech.
I was useing >10 & <10 or "A" as a example.
That is what I am trying to do. How would you code this concept if you were doing it.
Thank you for your help.
Dec 11 '06 #5
Killer42
8,435 Expert 8TB
Killer42 - Thank you for your help.
I am just trying to see if I can get this concept to work. I am trying to have any cell or any amount of cells on a worksheet make a "Sound" from the result of a formula is less then 10 (or if any letter "A") or have it speak a word if the same cell has a number from the results of a formula.
This would do the same thing as "Conditional Formatting" does with colors or fonts. This would do it with Wav Sounds and Speech.
I was useing >10 & <10 or "A" as a example.
That is what I am trying to do. How would you code this concept if you were doing it.
Thank you for your help.
I'm afraid I'm still having a little trouble understanding your intentions. Do you want the same thing to apply to everything on the sheet? Or do you wan to be able to somehow set this to happen for particular area, as with conditional formatting? The latter would be very simple, as you can just apply the value test to everything. For the latter, I'm not sure how you would go about identifying which ranges it applies to.

To refer back to your original code, I think my confusion really stems from the highlighted lines.
Expand|Select|Wrap|Line Numbers
  1. Private Declare Function sndPlaySound Lib "winmm.dll" _
  2.   Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
  3.   ByVal uFlags As Long) As Long
  4. Private Sub Worksheet_Change(ByVal Target As Excel.Range)
  5.   Dim strSound As String
  6.   Dim strtalk As String
  7.  
  8.   If Not Intersect(Target, Range("$A$1,$A$2,$A$3,$A$4,$A$5,$A$6,$B$2,$C$2")) Is Nothing Then
  9.     If Target.Column = 2 Or Target.Column = 3 Then
  10.       strSound = Choose(Target.Row, "Drumroll", "beep")
  11.       strtalk = Choose(Target.Row, "house and horn", "Dog  and  cat")
  12.     Else
  13.       strSound = Choose(Target.Row, "tada", "ding", "tada", "beep", "ding", "beep")
  14.       strtalk = Choose(Target.Row, "Dog", "Cat", "Pig", "House", "cat", "Rat")
  15.     End If
  16.     If Target.Value > 10 Then
  17.       sndPlaySound "C:\WINDOWS\Media\" & strSound, 0
  18.     End If
  19.     If Target.Value < 10 Then
  20.       Application.Speech.Speak strtalk, 0
  21.     End If
  22.   End If
  23. End Sub
  24.  
Is this intended to set different sounds per row, or what?
Dec 11 '06 #6
amx
8
Killer 42 - Thank you for your help.
I am trying to have as a example
Cell A1 <10 "wav tada" >10 "speak - dog"
Cell A3 <10 "wav ding" >10 "speak - cat"
Cell A6 <5 "wav drumroll" > 5 "speak - pig"

Cell B4 ="A" "wav beep" = "B" speak - house"

Cell C2 = <100 "wav tada" >100 "speak - horse"

Answers to your questions -
Q - Do you want the same thing to apply to everything on the sheet?
A - Only the cells that I choose (Example A1, A3, A6, B4, C2)

Q - do you want to be able to somehow set this to happen for particular area, as with conditional formatting
A - Yes only the cells that I choose just like conditional formatting

Q - I'm not sure how you would go about identifying which ranges it applies to.
A - That is the same problem that I am having on setting a different conditions
to cells that are in different place in a sheet and not in a range all togeather.

Q - I think my confusion really stems from the highlighted lines.
A - The highlighted area did not show up?


Q - Is this intended to set different sounds per row, or what?
A - It is intened to have different sounds and speech in each cell
the sounds and speech is different in every cell and every row
A sound for one condition and speech for another condition in the same cell
and each cell would stand on it's own.

I just wonder if Excel can do this. This would be a fancy conditional formatting

Thank you for your help.
I have been working on this for a while.
Dec 12 '06 #7
Killer42
8,435 Expert 8TB
Killer 42 - Thank you for your help.
I am trying to have as a example
Cell A1 <10 "wav tada" >10 "speak - dog"
Cell A3 <10 "wav ding" >10 "speak - cat"
Cell A6 <5 "wav drumroll" > 5 "speak - pig"

Cell B4 ="A" "wav beep" = "B" speak - house"

Cell C2 = <100 "wav tada" >100 "speak - horse"

Answers to your questions -
Q - Do you want the same thing to apply to everything on the sheet?
A - Only the cells that I choose (Example A1, A3, A6, B4, C2)

Q - do you want to be able to somehow set this to happen for particular area, as with conditional formatting
A - Yes only the cells that I choose just like conditional formatting

Q - I'm not sure how you would go about identifying which ranges it applies to.
A - That is the same problem that I am having on setting a different conditions
to cells that are in different place in a sheet and not in a range all togeather.
I don't know how you would tell Excel which sounds apply to which cells. Perhaps you could do something like setting a specific background or border colour for the cells to be targetted. And you could have another sheet on which you set up the relationship between colours and sounds.

Q - I think my confusion really stems from the highlighted lines.
A - The highlighted area did not show up?
Well, either you didn't follow what I meant, or your browser doesn't display these messages properly. Because in the Code box which followed that statement, some of the lines are shown in bold - this is what I meant when I said "highlighted lines".

Q - Is this intended to set different sounds per row, or what?
A - It is intened to have different sounds and speech in each cell
the sounds and speech is different in every cell and every row
A sound for one condition and speech for another condition in the same cell
and each cell would stand on it's own.
I just wonder if Excel can do this. This would be a fancy conditional formatting
I'm sure it can be done, in some way. As I said, it's just a matter of figuring out how to set up the relationships between locations and sounds. Using visible attributes may be the simplest, but may not be what you're looking for (for one thing, it may totally mess up your display). But it would allow you to fairly easily apply rules in your VBA code like "If cell has green background, play this sound".

I'm actually on holidays at the moment, so I might spend an hour or two (tomorrow, as it's almost time to finish up on the computer for the day) and see what I can come up with. I'm confident we can get something working fairly quickly, then you can play with it to your heart's content.
Dec 12 '06 #8
amx
8
Killer 42 - Thank you for your help.

I am still working on it also but with no luck.
I look foward to seeing what you might come up with.
I was not sure if Excel could do something like this.
Have a nice holiday. Thank you for taking time out of your holiday to help me.
Where are you having your holiday at?
Dec 12 '06 #9
Killer42
8,435 Expert 8TB
Killer 42 - Thank you for your help.

I am still working on it also but with no luck.
I look foward to seeing what you might come up with.
I was not sure if Excel could do something like this.
Have a nice holiday. Thank you for taking time out of your holiday to help me.
Where are you having your holiday at?
Well, I finally found some time to work on the pseudo-conditional-formatting idea. What I’ve come up with so far is certainly not a piece of work I’d be proud to display, but may provide some ideas, at any rate.

I’ll try to work out how (or if) I can attach it to this post, or a PM. Otherwise, I’ll try to get it to you via e-mail or something. Anyway…


Ok, the idea here is that you have your worksheet with your data on it, or where the user works. There is a corresponding worksheet which I’ve called “Flags” in my case, which the user should not touch (if you can hide it, all the better probably).

The user selects their cell (or range of cells) on the data sheet. One or more keypresses are set up to trigger a macro (or a bunch of macros), which sets the value of the cell(s) on the Flags sheet, in the locations corresponding to the selected cells. In other words, if you selected cells A1 to B3 then triggered the Set_A macro, it would place “A” in the Flags sheet, in cells A1, A2, A3, B1, B2, and B3.

In the Change event for the Data sheet, you invoke the ApplyRules macro, which for each of the specified cells will:
  • look up the value at the corresponding location in the Flags sheet
  • Find that value in the list of rules in column A on the Rules sheet
  • Paste the cell address of the user-entered value in the corresponding cell in column C on the Rules sheet
  • Paste the user-entered value in the corresponding cell in column B on the Rules sheet.
Your actual rules, to play the different sound files and so on, can then be applied to this small range of cells in the Rules sheet. The whole point of all the rest of this stuff is just to copy values to this point so the rules can be applied to them. (I couldn't get to TheScripts today to refresh my memory on what sort of rules you were applying. Oh well...)

I hope some of this makes sense.

To try it out, just select some cells in the Data sheet and run one of the “Set_” macros to set a rule (A, B, C or D) there. Have a look at the Flags sheet to see the effect. Obviously, you could get the same result by typing the A, B or whatever anywhere on the Flags sheet, too. But the idea is to have a key or a button for the end user to do the action.

Then enter some values in the Data sheet – preferably at least one in and one not in the cells you “set”. It should produce a message box showing what rule would be applied to the value you entered – including a default rule if you haven’t set one for that cell.

P.S. Well, I've just managed to get into TheScripts, pasted this message (written hours ago in Word) into a reply, and found that there's no facility for an attachment. Will have to work something out.

Ahah! When I went back to edit the message, I was able to add the attachment. :D
Attached Files
File Type: zip Flagging.zip (13.8 KB, 341 views)
Dec 14 '06 #10
amx
8
Killer 42 - Thank you for all of your work.
I am trying to make your code work and I found out that I am not very smart.
I have not been able to get it to work.
Would it be possible for you to please make up a working sheet with quite a few examples so I could understand what to do.
I understand your concept but I just get lost in the middle of setting it up.
Thank you for all of your hard work and knowledge.
Dec 14 '06 #11
Killer42
8,435 Expert 8TB
Killer 42 - Thank you for all of your work.
I am trying to make your code work and I found out that I am not very smart.
I have not been able to get it to work.
Would it be possible for you to please make up a working sheet with quite a few examples so I could understand what to do.
I understand your concept but I just get lost in the middle of setting it up.
Thank you for all of your hard work and knowledge.
No problem. My work was probably a bit confusing anyway. There's no reason to think you're dumb, just because you don't think the same way I do (few people do :)).

I should be able to get back to this in a couple of hours, so I'll try to create a couple of sample forms based on your speak/play rules.

Note that the main step which I haven't performed is to attach the Set_* macros to a key or button. I'm rather rusty in that area.
Dec 14 '06 #12
amx
8
Killer 42 - Thank you for your help.
I am still working on trying to make it work.
Dec 15 '06 #13
Killer42
8,435 Expert 8TB
Killer 42 - Thank you for your help.
I am still working on trying to make it work.
Sorry about the delay - been pretty busy.

Here's a quick sample. I just filled in rules A, B, C and D to play different sounds or speak different things (based on your original post) depending on whether a value entered on the Data sheet is over 10 or not. Try entering some values into the coloured cells, which are the ones I applied the rules to.

(In my case, the speech didn't work. I'd guess that's because I either have the wrong Excel version, don't have the speech set up, or haven't added a reference in the project. I'll leave that part to you, since I believe you already have that part working.)

To set or change the rule for a cell or range, you select it and run the appropriate macro (Set_A, Set_B etc).
Attached Files
File Type: zip Flagging-sample1.zip (15.8 KB, 141 views)
Dec 16 '06 #14
amx
8
Killer 42 - Thank you for all of your knowledge and hard coding work.
I have look over the code and that is very brillant and complex.
Your knowledge is very impressive. The sounds works on the sheet.
I will work on trying to make it work on different rows and columns and
see how much it can do.
Thank you very much for your help.
I hope you had a relax and enjoyable holiday.
Dec 17 '06 #15
Killer42
8,435 Expert 8TB
Killer 42 - Thank you for all of your knowledge and hard coding work.
I have look over the code and that is very brillant and complex.
Your knowledge is very impressive. The sounds works on the sheet.
I will work on trying to make it work on different rows and columns and
see how much it can do.
Thank you very much for your help.
Have fun!

The way to set the sounds for a row or column (or any range) is to put the "A" or "B" etc. in that range in the "Flags" sheet. You can do that directly on the Flags sheet, but the idea is to select the range in the Data sheet and run one of the Set_ macros to do it. Ideally, these macros should be assigned to buttons or something.

It would also be nice, I suppose, if you could see what rule is applied to a cell when you select it, but I didn't work on that part.

Anyway, I hope this gives you some ideas to work with.

I hope you had a relax and enjoyable holiday.
I still have another three weeks of holidays to go. :D
Dec 18 '06 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: Mark van Ballegooijen | last post by:
When using the XHTML 1.0 validator at http://validator.w3.org/check, an error will be raised for every instance of a "target" attribute in "A" elements. Is it truely because it is not part of this...
7
by: Clint Herron | last post by:
Howdy! I posted this question on CSharpCorner.com, but then realized I should probably post it on a more active newsgroup. This will be my only cross-post. I'm creating a game engine, and...
1
by: VB Programmer | last post by:
I have a datagrid which is bound to a datatable that I create on the fly. How do I set the width of each column via code? Ex: Column 1 is always 100, Column 2 is always 250, etc... Thanks!
3
by: sck10 | last post by:
Hello, I am dynamically building the following querystring: http://cost/content_ncb.aspx?qv01=101. How do I add Target=_blank? I have tried http://cost/content_ncb.aspx?qv01=101,Target=_blank...
2
by: Lethal Possum | last post by:
Hi all, I'm trying to make the following script work on Internet Explorer: function choose_target(form) { if (form.popup.checked == true) { form.target = '_blank'; } else { form.target =...
2
by: Hymer | last post by:
Hello, I have a small two-column table with three rows. The first column has a logo and the second column has the name of the organization. The logo's in the first column are too high. That...
5
by: Hymer | last post by:
Hello, I have a small two-column table with three rows. The first column has a logo and the second column has the name of the organization. The logo's in the first column are too high. That...
14
by: Arne | last post by:
A lot of Firefox users I know, says they have problems with validation where the ampersand sign has to be written as &amp; to be valid. I don't have Firefox my self and don't wont to install it only...
92
by: Erwin Moller | last post by:
Hi group, I encoutered page validation error, but I don't know a way around. The page has the following doctype: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.