Ok looks like Ive cracked it.
Private Sub UserForm_Initialize()
'Declate varibles - not all done yet
Dim lResult As Long, myRow As Range, Bcell As Range, Materialtype As String, Truckname As String
On Error GoTo errorhandler
'set screen updating to false because I active vehicle-material to find - would like to not have to do this
Application.ScreenUpdating = False
'Set all pages to visible - there must be a better way to do this!
Formpages = Me.MultiPage1.Pages.Count
counter = 1
Do Until counter = Formpages
Me.MultiPage1.Pages(counter).Visible = True
counter = counter + 1
Loop
'Determine what material type the have picked
Materialtype = ActiveCell.Offset(0, -2).Value
'Clean the string because named ranges dont have special characters
Materialtype = Replace(Materialtype, " ", "")
Materialtype = Replace(Materialtype, "-", "")
'set the counter for the page number (because I cannot get it to work
counter = 1
For Each Bcell In Range(Materialtype)
'incremented here as the data starts on row 2 (1 is the material header)
counter = counter + 1
'Clean the truckname as multipage names cannot contain spaces or &'s
Truckname = Sheets("Vehicle-Material").Cells(counter, 2).Value
Truckname = Replace(Truckname, " ", "")
Truckname = Replace(Truckname, "-", "")
Truckname = Replace(Truckname, "&", "")
'here I will check if there is an x, if not I will disable the page.
If Not Bcell.Value = "x" Then Me.MultiPage1.Pages(Truckname).Enabled = False
Next Bcell
Application.ScreenUpdating = True
errorhandler:
Application.ScreenUpdating = True
Exit Sub
End Sub
Nasty looking code though!
Bookmarks