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

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
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,214,864
Messages
6,121,981
Members
449,058
Latest member
oculus

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