Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Redim Preserve form a userform?
I wrote the following code to store values written in a userform. To be
written to the correct cells in a spreadsheet when another command button is clicked. The first time the comand button is clidcked it works. After that I get a subscript out of range message. The array is public and declared in a standard module. Private Sub CommandButton1_Click() Static counter As Integer counter = counter + 1 ReDim Preserve myarray(counter, 1 To 2) myarray(UBound(myarray, 1), 1) = TextBox1.Text ' This writes the contents of textbox1 ' to the first column of the last row in the ' array. myarray(UBound(myarray, 1), 2) = TextBox2.Text ' This writes the contents of textbox2 ' to the second column of the last row in the ' array. TextBox1.Text = "" TextBox2.Text = "" End Sub |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Redim Preserve form a userform?
You can't use redim preserve and change anything but the outermost dimension.
-- Regards, Tom Ogilvy "bobbo" wrote: I wrote the following code to store values written in a userform. To be written to the correct cells in a spreadsheet when another command button is clicked. The first time the comand button is clidcked it works. After that I get a subscript out of range message. The array is public and declared in a standard module. Private Sub CommandButton1_Click() Static counter As Integer counter = counter + 1 ReDim Preserve myarray(counter, 1 To 2) myarray(UBound(myarray, 1), 1) = TextBox1.Text ' This writes the contents of textbox1 ' to the first column of the last row in the ' array. myarray(UBound(myarray, 1), 2) = TextBox2.Text ' This writes the contents of textbox2 ' to the second column of the last row in the ' array. TextBox1.Text = "" TextBox2.Text = "" End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
VBA syntax help: ReDim Preserve an array | Excel Discussion (Misc queries) | |||
redim preserve the second dimension in a two-dim array | Excel Programming | |||
redim preserve | Excel Programming | |||
Redim Preserve doesn't work | Excel Programming | |||
ReDim, Preserve and Multidimensional arrays | Excel Programming |