M
M. Authement
I have two procedures that use SpecialCells(xlFormulas) to reduce a range to
only those cells that contain formulas. In the first instance the original
range is derived from a form and in the second it is derived from the user
selection. In testing these procedures out, only the first one is working.
The test cells contain the text 'alpha', 'beta', 'gamma', 'delta'. In the
first procedure I get a message box saying no formulas were found. In the
second I get an error later on in the procedure because the rest of the
procedure relys on formulas being present. I have looked at this for way
too long and can not find the problem.
Procedure 1:
bNoFormulas = False
If Range(frmAddServer.refInputRng.Value).Count > 1 Then
On Error Resume Next
Set rngInput =
Range(frmAddServer.refInputRng.Value).SpecialCells(xlFormulas, 23)
On Error GoTo ErrorHandler
If rngInput Is Nothing Then 'There are no formulas in the range
bNoFormulas = True
End If
Else
Set rngInput = Range(frmAddServer.refInputRng.Value)
If Not rngInput.HasFormula Then
bNoFormulas = True
End If
End If
If bNoFormulas Then
MsgBox Prompt:=mcsMSG_NO_FORM, Buttons:=vbOKOnly + vbInformation,
Title:=mcsMODTITLE
Err.Raise glUSER_CANCEL
End If
Procedure 2 (not working):
On Error Resume Next
Set rngInput = Selection
On Error GoTo ErrorHandler
If rngInput Is Nothing Then
MsgBox Prompt:=mcsMSG_NO_SELECTION, Buttons:=vbOKOnly +
vbInformation, Title:=mcsMODTITLE
Err.Raise glUSER_CANCEL
End If
bNoFormulas = False
If rngInput.Count > 1 Then
On Error Resume Next
Set rngInput = rngInput.SpecialCells(xlFormulas, 23)
On Error GoTo ErrorHandler
If rngInput Is Nothing Then 'There are no formulas in the range
bNoFormulas = True
End If
Else
If Not rngInput.HasFormula Then
bNoFormulas = True
End If
End If
If bNoFormulas Then
MsgBox Prompt:=mcsMSG_NO_FORM, Buttons:=vbOKOnly + vbInformation,
Title:=mcsMODTITLE
Err.Raise glUSER_CANCEL
End If
only those cells that contain formulas. In the first instance the original
range is derived from a form and in the second it is derived from the user
selection. In testing these procedures out, only the first one is working.
The test cells contain the text 'alpha', 'beta', 'gamma', 'delta'. In the
first procedure I get a message box saying no formulas were found. In the
second I get an error later on in the procedure because the rest of the
procedure relys on formulas being present. I have looked at this for way
too long and can not find the problem.
Procedure 1:
bNoFormulas = False
If Range(frmAddServer.refInputRng.Value).Count > 1 Then
On Error Resume Next
Set rngInput =
Range(frmAddServer.refInputRng.Value).SpecialCells(xlFormulas, 23)
On Error GoTo ErrorHandler
If rngInput Is Nothing Then 'There are no formulas in the range
bNoFormulas = True
End If
Else
Set rngInput = Range(frmAddServer.refInputRng.Value)
If Not rngInput.HasFormula Then
bNoFormulas = True
End If
End If
If bNoFormulas Then
MsgBox Prompt:=mcsMSG_NO_FORM, Buttons:=vbOKOnly + vbInformation,
Title:=mcsMODTITLE
Err.Raise glUSER_CANCEL
End If
Procedure 2 (not working):
On Error Resume Next
Set rngInput = Selection
On Error GoTo ErrorHandler
If rngInput Is Nothing Then
MsgBox Prompt:=mcsMSG_NO_SELECTION, Buttons:=vbOKOnly +
vbInformation, Title:=mcsMODTITLE
Err.Raise glUSER_CANCEL
End If
bNoFormulas = False
If rngInput.Count > 1 Then
On Error Resume Next
Set rngInput = rngInput.SpecialCells(xlFormulas, 23)
On Error GoTo ErrorHandler
If rngInput Is Nothing Then 'There are no formulas in the range
bNoFormulas = True
End If
Else
If Not rngInput.HasFormula Then
bNoFormulas = True
End If
End If
If bNoFormulas Then
MsgBox Prompt:=mcsMSG_NO_FORM, Buttons:=vbOKOnly + vbInformation,
Title:=mcsMODTITLE
Err.Raise glUSER_CANCEL
End If