Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 56
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA syntax help: ReDim Preserve an array Dave Excel Discussion (Misc queries) 4 September 8th 07 07:37 PM
redim preserve the second dimension in a two-dim array Arnold Klapheck Excel Programming 4 September 19th 06 02:10 PM
redim preserve [email protected][_2_] Excel Programming 3 December 15th 05 01:40 PM
Redim Preserve doesn't work Witek[_2_] Excel Programming 3 November 1st 04 11:34 PM
ReDim, Preserve and Multidimensional arrays Andy Westlake[_2_] Excel Programming 3 October 19th 04 07:04 PM


All times are GMT +1. The time now is 07:17 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"