PDA

View Full Version : Solved: Type miss match



chungtinhlak
12-18-2008, 12:43 PM
I have the following textboxes in my userform. Where txtsheet allows the user to input sheet name.

In my code, I have
wkbworking.activate
sheets(userform1.sheet).Select ' this gives me a type mismatch

and also tried

sheets("'" & userform1.sheet & """).Select

this gives me Subscript out of range

What did i do wrong




Private Sub UserForm_Initialize()
UserForm1.txtcognos.Value = "Line 6 Soi"
UserForm1.txtip.Value = "IP Assessments LN6"
UserForm1.txtsheet.Value = "LN6"
UserForm1.txtsoi.Value = "A"
UserForm1.txtResult.Value = "P"

End Sub

Cosmo
12-18-2008, 12:56 PM
Is 'userform1.sheet' a userform field (or is it named 'txtsheet')?


Try using the field's value:

sheets(userform1.sheet.Value).Select

xld
12-18-2008, 01:00 PM
A userform doesn't have a sheet property.

Maybe you want



sheets(userform1.txtSheet.Text).Select

chungtinhlak
12-18-2008, 01:32 PM
sheets(userform1.txtSheet.Text).Select


Subscript out of range.

txtsheet is a textbox in my userform

Mahahaava
12-18-2008, 03:04 PM
Hi,

this works:

Sub test()
Workbooks("LAN").Sheets(UserForm1.txtsheet.Value).Select
MsgBox "Active sheet: " & ActiveSheet.Name
End Sub
/Petri

chungtinhlak
12-19-2008, 08:48 AM
thanks