PDA

View Full Version : Solved: Return data from Userform to a specifik worksheet cell



ulfal028
02-03-2006, 01:44 AM
Hi,
I'm using a single userform that imports data from 32 different rows, depending on how you open the userform.
Now, the problem is how I return the userform selection to one specific cell/row.

Example:
IF [Userform] Label22.Value = 1 THEN 'send data to worksheet row 1, etc

Thanx!

tpoynton
02-03-2006, 05:45 AM
if i understand your question correctly, you are just looking to copy a range from one part of the worksheet to another? or is it modified in the userform?

if you are copying a row from one place to another, this would work:
Range("A1:Z1").Value = Range("A3:Z3").Value
what are "the data"? an example would be helpul...

ulfal028
02-03-2006, 06:31 AM
You're right. When the userform is opened, depending on how you open it, Label1 is asigned a number between 1 to 3. Then I alter some things in the userform, and wishes to return the new value of Label2 to the worksheet corresponding to a specific row.

Example:
Label1 is 1, then values back to A1
Label1 is 2, then values back to A2
...and so on. My code doesn't work:
Private Sub CommandButton1_Click()
If Label1.Value = 1 Then ActiveSheet.Range("A1") = Label2
ElseIf Label1.Value = 2 Then ActiveSheet.Range("A2") = Label2
ElseIf Label1.Value = 3 Then ActiveSheet.Range("A3") = Label2
End If
End Sub

Hope I've explained the problem.

tpoynton
02-03-2006, 06:38 AM
SO you are returning the value of the label to a specific cell?

i would use:

If Label1.Value = 1 Then Cells(1, 1).Value = Label2.Value
ElseIf Label1.Value = 2 Then Cells(1, 2).Value = Label2.Value

and so on - tim

ulfal028
02-03-2006, 08:23 AM
Yes, although my code doesn't work... I'm attaching an example.

Norie
02-03-2006, 08:42 AM
Labels do not have a Value property.:)

tpoynton
02-03-2006, 08:50 AM
my apologies; that's what i get for not testing!

i believe the attached file does what you want...tim

ulfal028
02-05-2006, 11:40 AM
I'm afraid it's still not working... I'm getting a 1004 error when clicking the user form command button... :/

mdmackillop
02-05-2006, 01:47 PM
Private Sub CommandButton1_Click()
Dim i As Long
i = Label1.Caption
Cells(i, 1).Value = Label2.Caption
Unload UserForm1
End Sub

ulfal028
02-06-2006, 01:37 AM
Finally.. Thanks a lot, man.