User Form - Finding the value in an Array

K

K2G

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
 
D

Dave Peterson

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!"
 
K

K2G

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!"

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top