![]() |
Arrays and cell values
hi there im having trouble with adding values to a cell and linking them to my arrays. basicly what i want to do is input the number from 1-5 into cell F12, this representing a vote for a radio program. once the number 1-5 has been put into the cell i then want to add the integer one to the corrisponding cell for that radio programe that i have created. but im having alot of trouble doing this. i can get one to be added to the first cell in my table if i put < in but this is not what i want. i want the number be to be loked up in the array and then 1 to be added onto the score each time. the below is the coding that i have done so far, please can someone help me it is driving me around the bend, because i am new to VBA programming and im having alot of trouble understanding it all. Private Sub Submit_Click() Dim radioProgramName(5) As String, radioProgramNumber(5) As Single Dim submitScore As Integer radioProgramName(1) = "talk sport" radioProgramName(2) = "talk garden" radioProgramName(3) = "talk DIY" radioProgramName(4) = "talk talk" radioProgramName(5) = "talk weather" radioProgramNumber(1) = 1 radioProgramNumber(2) = 2 radioProgramNumber(3) = 3 radioProgramNumber(4) = 4 radioProgramNumber(5) = 5 'this is another way of holding the data in an array i think but i am not sure so i have done it the other way below too. 'radioProgramName(5) = Array("talk sport", "talk garden", "talk DIY", "talk talk", "talk weather") 'radioProgramNumber(5) = Array("54", "98", "45", "63", "30") If Range("f12").Select = "1" Then submitScore = Range("f12").Value = Range("d12").Value Range("d12").Value = Range("d12").Value + 1 End If If Range("f12").Select = "2" Then submitScore = Range("f12").Value = Range("d13").Value Range("d13").Value = Range("d13").Value + 1 End If If Range("f12").Select = "3" Then submitScore = Range("f12").Value = Range("d14").Value Range("d14").Value = Range("d14").Value + 1 End If If Range("f12").Select = "4" Then submitScore = Range("f12").Value = Range("d15").Value Range("d15").Value = Range("d15").Value + 1 End If If Range("f12").Select = "5" Then submitScore = Range("f12").Value = Range("d16").Value Range("d16").Value = Range("d16").Value + 1 End If End Sub -- RELWOD85 ------------------------------------------------------------------------ RELWOD85's Profile: http://www.excelforum.com/member.php...o&userid=25753 View this thread: http://www.excelforum.com/showthread...hreadid=393046 |
Arrays and cell values
There is nothing in your code to indicate any use of the array.
To increment one of the cells D12 - D16 based on the value if F12 if isnumeric(Range("F12").Value) then set rng = Range("d12").Offset(Range("F12").Value-1,0).Value rng.value = rng.value + rng1.Value End if a construct like this submitScore = Range("f12").Value = Range("d12").Value says that submitScore will hold the result of the logical comparison of the values in F12 and D12. If they are equal, it will hold true. If they are not equal, it will hold false. (since you declare submitscore as type integer, false would be coerced to 0 and true would be coerced to -1) -- Regards, Tom Ogilvy "RELWOD85" wrote in message ... hi there im having trouble with adding values to a cell and linking them to my arrays. basicly what i want to do is input the number from 1-5 into cell F12, this representing a vote for a radio program. once the number 1-5 has been put into the cell i then want to add the integer one to the corrisponding cell for that radio programe that i have created. but im having alot of trouble doing this. i can get one to be added to the first cell in my table if i put < in but this is not what i want. i want the number be to be loked up in the array and then 1 to be added onto the score each time. the below is the coding that i have done so far, please can someone help me it is driving me around the bend, because i am new to VBA programming and im having alot of trouble understanding it all. Private Sub Submit_Click() Dim radioProgramName(5) As String, radioProgramNumber(5) As Single Dim submitScore As Integer radioProgramName(1) = "talk sport" radioProgramName(2) = "talk garden" radioProgramName(3) = "talk DIY" radioProgramName(4) = "talk talk" radioProgramName(5) = "talk weather" radioProgramNumber(1) = 1 radioProgramNumber(2) = 2 radioProgramNumber(3) = 3 radioProgramNumber(4) = 4 radioProgramNumber(5) = 5 'this is another way of holding the data in an array i think but i am not sure so i have done it the other way below too. 'radioProgramName(5) = Array("talk sport", "talk garden", "talk DIY", "talk talk", "talk weather") 'radioProgramNumber(5) = Array("54", "98", "45", "63", "30") If Range("f12").Select = "1" Then submitScore = Range("f12").Value = Range("d12").Value Range("d12").Value = Range("d12").Value + 1 End If If Range("f12").Select = "2" Then submitScore = Range("f12").Value = Range("d13").Value Range("d13").Value = Range("d13").Value + 1 End If If Range("f12").Select = "3" Then submitScore = Range("f12").Value = Range("d14").Value Range("d14").Value = Range("d14").Value + 1 End If If Range("f12").Select = "4" Then submitScore = Range("f12").Value = Range("d15").Value Range("d15").Value = Range("d15").Value + 1 End If If Range("f12").Select = "5" Then submitScore = Range("f12").Value = Range("d16").Value Range("d16").Value = Range("d16").Value + 1 End If End Sub -- RELWOD85 ------------------------------------------------------------------------ RELWOD85's Profile: http://www.excelforum.com/member.php...o&userid=25753 View this thread: http://www.excelforum.com/showthread...hreadid=393046 |
All times are GMT +1. The time now is 06:59 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com