Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 287
Default Issue passing data from sheet into userform

Hi,
I am having an issue passing data from a worksheet into a userform. The
situation is that I have two forms. One form being the main form where the
user inputs data and the VBA code enters the data in an excel sheet. Each
time the user enters a set of data(row) and clicks the button to add the
data, the row or set of data gets an index number. So the Sheet would be
something like this,
Index Type Size
1..........3C.....#3/0
2..........3C.....#2/0 ...etc

Now, I have a button on my main form(Userform) called modify that opens up
another form. The code that I have to open my Modify form(frmMod) is:

--(This is in the UserForm code)--
Private Sub cmdModify_Click()
UserForm.Hide
Load frmMod
frmMod.Show
End Sub

Now the modify form is where the user selects the index for the row of data
they want to modify. So the user selects this number from a combo box
(cmbIndex). The user then selects an ok button which runs VBA code to go to
the user inputted data, match the index numbers and then populate the main
form with the data from the row and close the modify form. Here is the OK
event code for the modify form:

--(This is in the frmMod code)--
Private Sub cmdOK_Click()
Dim x As Integer
Dim y As Integer
If cmbIndex.Value < "" Then
Range(REF_CELL).Select 'Start at the top of the
index list
ActiveCell.Offset(1, 0).Select 'Move down one cell to
go past the header

Do Until IsEmpty(ActiveCell) = True 'Scroll down until at
the end of the index list
x = ActiveCell.Value 'x= current index value
as code moves down list
y = cmbIndex.Value 'y= user selected index
value
If x = y Then 'When index matches user
selected index

**** UserForm.cmbVoltage.Value = "5kV"
UserForm.txtQuantity.Text = ActiveCell.Offset(0, 1).Value
UserForm.cmbType.Value = "3C"
UserForm.cmbSize.Value = ActiveCell.Offset(0, 2).Value
UserForm.txtDescription.Text = ActiveCell.Offset(0, 3).Value
UserForm.cmbControlCable.Value = ActiveCell.Offset(0, 4).Value
Exit Do

End If
ActiveCell.Offset(1, 0).Select 'Move down a cell every
loop iteration
Loop
UserForm.Show 'Show the userform
Unload frmMod 'Close the Modify form
End If
End Sub

The issue is that when the code goes to assign the values at the line
denoted with '****', it goes to the userform_initialize event which I do not
think should happen since I only used userform.hide. Also, the code does not
continue running past the **** line since it reinitializes the userform. This
is behavior I am not expecting and I am at a loss as to how to correct it or
as to why it is happening. Sorry bout the long msg but wanna make sure any
helpful info is there.
Thanks for any help in advance,
--
Aaron
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Issue passing data from sheet into userform

Sorry, but I don't have time to read all of your code. Anyway, this is how I
pass data from a sheet to a UserForm:

Name a TextBox, such as 'Number'

VBA Code under UserForm:
Private Sub UserForm_Activate()
On Error Resume Next
Number.Text = Cells(1, 1) ' (1, 1) = Down 1 cell and over one cell, so A1
Account.Text = Cells(2, 1) ' (2, 1) = Down 2 cells and over one cell, so A2
'And so on and so forth
On Error Resume Next
End Sub

If you want to add formatting, use this technique:
TextBox1.Text = Format(Cells(1, 1), "#,##0.00") ' For decimalization
TextBox1.Text = Format(Cells(1, 1), "##0.00%") ' For percentages

Regards,
Ryan---
--
RyGuy


"Aaron" wrote:

Hi,
I am having an issue passing data from a worksheet into a userform. The
situation is that I have two forms. One form being the main form where the
user inputs data and the VBA code enters the data in an excel sheet. Each
time the user enters a set of data(row) and clicks the button to add the
data, the row or set of data gets an index number. So the Sheet would be
something like this,
Index Type Size
1..........3C.....#3/0
2..........3C.....#2/0 ...etc

Now, I have a button on my main form(Userform) called modify that opens up
another form. The code that I have to open my Modify form(frmMod) is:

--(This is in the UserForm code)--
Private Sub cmdModify_Click()
UserForm.Hide
Load frmMod
frmMod.Show
End Sub

Now the modify form is where the user selects the index for the row of data
they want to modify. So the user selects this number from a combo box
(cmbIndex). The user then selects an ok button which runs VBA code to go to
the user inputted data, match the index numbers and then populate the main
form with the data from the row and close the modify form. Here is the OK
event code for the modify form:

--(This is in the frmMod code)--
Private Sub cmdOK_Click()
Dim x As Integer
Dim y As Integer
If cmbIndex.Value < "" Then
Range(REF_CELL).Select 'Start at the top of the
index list
ActiveCell.Offset(1, 0).Select 'Move down one cell to
go past the header

Do Until IsEmpty(ActiveCell) = True 'Scroll down until at
the end of the index list
x = ActiveCell.Value 'x= current index value
as code moves down list
y = cmbIndex.Value 'y= user selected index
value
If x = y Then 'When index matches user
selected index

**** UserForm.cmbVoltage.Value = "5kV"
UserForm.txtQuantity.Text = ActiveCell.Offset(0, 1).Value
UserForm.cmbType.Value = "3C"
UserForm.cmbSize.Value = ActiveCell.Offset(0, 2).Value
UserForm.txtDescription.Text = ActiveCell.Offset(0, 3).Value
UserForm.cmbControlCable.Value = ActiveCell.Offset(0, 4).Value
Exit Do

End If
ActiveCell.Offset(1, 0).Select 'Move down a cell every
loop iteration
Loop
UserForm.Show 'Show the userform
Unload frmMod 'Close the Modify form
End If
End Sub

The issue is that when the code goes to assign the values at the line
denoted with '****', it goes to the userform_initialize event which I do not
think should happen since I only used userform.hide. Also, the code does not
continue running past the **** line since it reinitializes the userform. This
is behavior I am not expecting and I am at a loss as to how to correct it or
as to why it is happening. Sorry bout the long msg but wanna make sure any
helpful info is there.
Thanks for any help in advance,
--
Aaron

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
Classes and Userform: Passing it around axwack Excel Programming 2 September 5th 07 01:47 PM
Passing value to userform quetion Doug Glancy Excel Programming 0 December 1st 06 09:02 PM
Passing Variable from Sheet to Userform gti_jobert[_40_] Excel Programming 1 February 27th 06 09:38 AM
Passing variables between Sub and Userform jose luis Excel Programming 8 July 22nd 05 05:20 PM
passing data from one sheet to another billabong Excel Programming 4 July 13th 03 01:15 AM


All times are GMT +1. The time now is 09:02 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"