loop controls through multipage & frame on userform

MKLAQ

Board Regular
Joined
Jan 30, 2021
Messages
188
Office Version
  1. 2016
Platform
  1. Windows
hello
I have this form as in picture and it doesn't copy the values from controls to ranges in sheet
so what suggest to do that ?
VBA Code:
Private Sub CommandButton1_Click()
Dim lr As Integer
Dim ctrl As Control
With sheet1
lr = .Range("c" & Rows.Count).End(xlUp).Row + 1

r = UserForm1.MultiPage1.Value
For Each ctrl In UserForm1.MultiPage1.Pages(r).Controls
If TypeName(ctrl) = "textbox" & "combobox" Then

.Range("a" & lr) = Me.TextBox1
.Range("B" & lr) = Me.TextBox2

.Range("c" & lr) = Me.ComboBox1
End If
Next ctrl
End With
End Sub
1.JPG



thanks
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Saurabhj

Active Member
Joined
Jun 6, 2020
Messages
457
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi,

Use below code:

VBA Code:
Private Sub CommandButton1_Click()
    Dim lr As Integer
    Dim ctrl As Control
    With Sheets("Sheet1")
        lr = .Cells(Rows.Count, "C").End(xlUp).Row + 1
        
        r = UserForm1.MultiPage1.Value
        For Each ctrl In UserForm1.MultiPage1.Pages(r).Controls
            If TypeName(ctrl) = "TextBox" Or TypeName(ctrl) = "ComboBox" Then
                .Range("a" & lr) = Me.TextBox1
                .Range("B" & lr) = Me.TextBox2
                .Range("c" & lr) = Me.ComboBox1
            End If
        Next ctrl
    End With

End Sub
 
Solution

MKLAQ

Board Regular
Joined
Jan 30, 2021
Messages
188
Office Version
  1. 2016
Platform
  1. Windows
great updating ! many thanks buddy :)
 

Saurabhj

Active Member
Joined
Jun 6, 2020
Messages
457
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
My Pleasure. Thanks for the feedback.
 

Forum statistics

Threads
1,141,127
Messages
5,704,442
Members
421,349
Latest member
Santhosh3188

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
Top