![]() |
User Form - Finding the value in an Array
Hello all,
I am developing a spreadsheet that contains a series of User Form. One of then uses a combo box and a list box, The user selects an account (a row in an Array) from the combo box and then he selects one item from the list box (Column head in the array) that will receive a new value, i.e., once he clicks the Ok button the array where the data is will change only the selected item, leaving all the other as they were previously. I am new to VBA, therefore having a hard time in developing the code for doing that. I would appreciate getting some help from anyone who has faced similar needs. Thanks all in advance, K |
User Form - Finding the value in an Array
Is this array a multicolumn range--or is it a real array (in code)?
If it's a range, you may be able to do something like: dim myRow as Variant 'could be an error dim myCol as Variant 'could be an error dim myRng as range dim myCell as range With worksheets("Somesheetnamehere") set myrng = .range("a1:G" & .cells(.rows.count,"A").end(xlup).row) end with myrow = application.match(me.combobox1.value, myrng.columns(1), 0) myCol = application.match(me.listbox1.value, myrng.rows(1),0) if iserror(myrow) _ or iserror(mycol) then msgbox "Design error--there is no match!" exit sub end if set mycell = myrng(myrow,mycol) mycell.value = "This is the cell!" K2G wrote: Hello all, I am developing a spreadsheet that contains a series of User Form. One of then uses a combo box and a list box, The user selects an account (a row in an Array) from the combo box and then he selects one item from the list box (Column head in the array) that will receive a new value, i.e., once he clicks the Ok button the array where the data is will change only the selected item, leaving all the other as they were previously. I am new to VBA, therefore having a hard time in developing the code for doing that. I would appreciate getting some help from anyone who has faced similar needs. Thanks all in advance, K -- Dave Peterson |
User Form - Finding the value in an Array
On 10 jul, 09:29, Dave Peterson wrote:
Is this array a multicolumn range--or is it a real array (in code)? If it's a range, you may be able to do something like: dim myRow as Variant 'could be an error dim myCol as Variant 'could be an error dim myRng as range dim myCell as range With worksheets("Somesheetnamehere") * set myrng = .range("a1:G" & .cells(.rows.count,"A").end(xlup).row) end with myrow = application.match(me.combobox1.value, myrng.columns(1), 0) myCol = application.match(me.listbox1.value, myrng.rows(1),0) if iserror(myrow) _ *or iserror(mycol) then * msgbox "Design error--there is no match!" * exit sub end if set mycell = myrng(myrow,mycol) mycell.value = "This is the cell!" K2G wrote: Hello all, I am developing a spreadsheet that contains a series of User Form. One of then uses a combo box and a list box, The user selects an account (a row in an Array) from the combo box and then he selects one item from the list box (Column head in the array) that will receive a new value, i.e., once he clicks the Ok button the array where the data is will change only the selected item, leaving all the other as they were previously. I am new to VBA, therefore having a hard time in developing the code for doing that. I would appreciate getting some help from anyone who has faced similar needs. Thanks all in advance, K -- Dave Peterson Hello again Dave, I tried out your suggestion, but I get the message that the value I am looking for is not in the Range, which is not right... I think you got the right idea of what I am trying to do. If you have any other suggestion, I greatly appreciate, otherwise, thanks anyway!! K |
All times are GMT +1. The time now is 11:29 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com