so in my previous code, i left it at UserForm3. and i have the routine below to handle that. but since changing it to btn_Gen, now i get an "object error" because the routine checks for all loaded userforms. so how can i expose all the userforms named userform#.

```
QtyUF = miNoOfUserForms + 1
ufName = "UserForm" & QtyUF
```

and here is the function:

```
Function miNoOfUserForms() As Integer
Const iUSERFORM_TYPE As Integer = 3
Dim iNoOfUserForms As Integer
Dim objVBComponent As Object
iNoOfUserForms = 0
For Each objVBComponent In ThisWorkbook.VBProject.VBComponents
If objVBComponent.Type = iUSERFORM_TYPE Then
iNoOfUserForms = iNoOfUserForms + 1
End If
Next objVBComponent
miNoOfUserForms = iNoOfUserForms
End Function
```

so the function returns the number of total userforms when i need it to return the number of userforms named userform#

if you need to see the file, it is here on excelforum.

https://www.excelforum.com/excel-programming-vba-macros/1267352-cross-posted-from-wellsr-com-getting-a-subscript-out-of-range.html#post5078774