Userform data to Excel Worksheet

trishgyrl

New Member
Joined
Jan 16, 2018
Messages
21
Hello. This may be a simple question but, I am new to this.

I would like the caption of each visible label to show in rows of column A and the value of the textbox to go in rows of column B.

On the nextrow2 variable, I'm getting an error that say "object does not support this property or method." Please help. Thanks in advance.

Code:
[FONT=Verdana]Dim nextrow As Long[/FONT]
Dim nextrows As Long 
Dim ctrl As Control 
 
Dim ws As Worksheet 
 
If bComplete Then 
     
    Set ws = Worksheets("Sheet2") 
    ws.Select 
     
     [COLOR=darkgreen]'determine the next empty row[/COLOR]
    nextrow = FindLastRow(ws, "A") + 1 
    nextrows = FindLastRow(ws, "B") + 1 
     
     [COLOR=darkgreen]'transfer the control values[/COLOR]
     
    For Each ctrl In Me.Controls 
        If ctrl.Visible Then 
             
            If TypeName(ctrl) = "TextBox" Then 
                 
                ws.Cells(nextrow, 1) = ctrl.Value 
                nextrow = nextrow + 1 
            Else 
                 
                If TypeName(ctrl) = "Label" Then 
                     
                    ws.Cells(nextrows, 2) = ctrl.Value 
                    nextrows = nextrows + 1 
                End If 
            End If 
        End If 
    Next ctrl 
     
     
     
    Unload Me 

[FONT=Verdana]End If[/FONT]

 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Labels don't have a Value property, to get the caption use the Caption property.
Code:
ws.Cells(nextrows,2) = ctrl.Caption
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top