View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
[email protected] adam_kroger@hotmail.com is offline
external usenet poster
 
Posts: 20
Default Using named Excel range in VBA

Part of my original problem was that the range names were not properly
declared.

I worked with it a bit and got it to almost work. except for some
reason, when it formats for "Time" the data validation does not
operate with the dropdown when the ComboBox value changes. If I go in
and run the Sub manually from the VBE interface the dropdown list
appears, but not when the ComboBox is changed from the worksheet. I
don't understand why...

Without the "On Error" statement I get a runtime error that states:
"Run-time error '-2147417848(80010108)':
Automation error
The object invoked has disconnected from its clients"

**The long list of WorkSheet names, and the comma seperated time list,
are removed from the Subs/Functions below for visual formatting

Private Sub Type1_Change() '------there are 28 subs
like this one for ComboBoxes
If Type1.Text = "Time" Or Type1.Text = "Qty" Or Type1.Text = "N/A"
Then
Call CatFormat("CATr1", Type1.Text)
End If
End Sub
================================================== ============
Function CatFormat(MyCat As String, CatVal As String)
Dim MySheets, i As Integer
MySheets = Array ( ***list of 16 worksheet names***)
If CatVal = "Time" Then
For i = 0 To 15
With Sheets(MySheets(i)).Range(MyCat).Validation
.Delete
On Error Resume Next
.Add xlValidateList, xlValidAlertStop, xlBetween, "
***0 through 8:00 in 0:15 incriments***
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
Sheets(MySheets(i)).Range(MyCat).NumberFormat = "[h]:mm"
Next i
Else
For i = 0 To 15
With Sheets(MySheets(i)).Range(MyCat).Validation
.Delete
On Error Resume Next
.Add Type:=xlValidateWholeNumber,
AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:="0",
Formula2:="999"
.IgnoreBlank = True
.InCellDropdown = False
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
Sheets(MySheets(i)).Range(MyCat).NumberFormat = "0"
Next i
End If
End Function