You are on page 1of 5

Tool Image Property

Name FrmGeneral

1 Userform
Caption General Information

Name Page1
Caption Personal Information
1 Multipage
Name Page2
Caption My Favorite Painting
Name Label1
Caption Name
2 Label Name Label2
Caption Age

Name TxtName
2 Textbox
Name TxtAge
Name Frame1

1 Frame

Caption Gender

Name OptionButton1
Option Caption Male
2
Button Name OptionButton2
Caption Female

Tool Image Property


Name Label3
1 Label
Caption Favorite Painting

1 Listbox Name LstPaint

1 Image Name ImgPaint

Name CmdOK
1 Commandbutton
Caption OK
Coding
Option Explicit

Private Sub CommandButton1_Click()

Dim emptyRow As Long

'Make Sheet1 active


Sheet1.Activate

'Determine emptyRow
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1

'Transfer information
Cells(emptyRow, 1).Value = TextBox1.Value
Cells(emptyRow, 2).Value = TextBox2.Value

If OptionButton1.Value = True Then


Cells(emptyRow, 3).Value = "Male"
Else
Cells(emptyRow, 3).Value = "Female"
End If

Cells(emptyRow, 4).Value = ListBox1.Value

'Close Userform
Unload Me

End Sub

Private Sub ListBox1_Click()

If ListBox1.ListIndex = 0 Then
Image1.Picture = LoadPicture("C:\test\Mountains.jpg")
End If

If ListBox1.ListIndex = 1 Then
Image1.Picture = LoadPicture("C:\test\Sunset.jpg")
End If

If ListBox1.ListIndex = 2 Then
Image1.Picture = LoadPicture("C:\test\Beach.jpg")
End If

If ListBox1.ListIndex = 3 Then
Image1.Picture = LoadPicture("C:\test\Winter.jpg")
End If

End Sub
Private Sub UserForm_Initialize()

With ListBox1
.AddItem "Mountains"
.AddItem "Sunset"
.AddItem "Beach"
.AddItem "Winter"
End With

End Sub
MyList

=OFFSET(Example!$A$1;0;0;COUNTA(Example!$A:$A))

Private Sub CmdChoose_Click()


Mensa.Caption = ListBox1.Value
End Sub

Private Sub UserForm_Initialize()

ListBox1.RowSource = "EXAMPLE!A1:A" & Range("A" & Rows.Count).End(xlUp).Row

End Sub

Sheet

Private Sub CommandButton1_Click()


UserForm2.Show
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)


If Not Intersect(Target, Range("A:A")) Is Nothing Then
With ComboBox1
.Value = ""
.ListFillRange = "= MyList"
End With
End If
End Sub

Private Sub UserForm_Initialize()

Dim rango, celda As Range


Set rango = Range("MyList")

For Each celda In rango


ComboBox1.AddItem celda.Value
Next celda

End Sub

You might also like