J
Jac Tremblay
Hi everyone
I'm trying to list some information on validations that are present in some columns of a workbook (with 24 worksheets). I will eventually have to reconstruct these validations on other workbooks
There are 2 types of validations. Either: 1- a list of values that gets its data from a named range and 2- a text length validation of the type "<= 5 characters"
I want to know how to skip a cell that do not contain a validation. The code I wrote gives an error and stops
I also want to distinguish between a validation that shows a list of values and a text length validation (the information to gather is different)
Where can I get the constant names and corresponding numbers (Type property xlValidateTextLength = 6, Operator xlLessEqual = 8, etc.)
Here is some of my code
'******************************************************************
Sub ListValidations(
Dim intNbSheets As Intege
Dim strWorkbook As Strin
Dim intI As Intege
Dim strSheetName As Strin
Dim intNoCol As Intege
Dim intNbColToDo As Intege
Dim strLetter As Strin
Dim strAddresse As Strin
Dim strValidation As Validatio
Dim strType As Strin
Dim strAlertStyle As Strin
Dim strOperator As Strin
Dim strFormula1 As Strin
Dim strFormula2 As Strin
Dim strValue As Strin
strWorkbook = ActiveWorkbook.Nam
intNbSheets = ActiveWorkbook.Sheets.Coun
' Activate utility worksheet
On Error GoTo ErrUtilityWorkshee
Windows("Utility.xls").Activat
Sheets("Lists of values").Activat
Range("A2:B20").Selec
Range("A2").Activat
Selection.Clea
Range("A2").Selec
Range("A2").Value = strWorkboo
Selection.Font.Bold = Tru
Range("A3").Selec
Windows(strWorkbook).Activat
For intI = 1 To intNbSheets -
Workbooks(strWorkbook).Sheets(intI).Activat
strSheetName = ActiveWorkbook.Sheets(intI).Nam
Windows("Utility.xls").Activat
ActiveCell.Value = "Sheet no " & int
Selection.Font.Bold = Tru
ActiveCell.Offset(0, 1).Selec
ActiveCell.Value = strSheetNam
Selection.Font.Bold = Tru
ActiveCell.Offset(1, -1).Selec
' Find out the number of columns to do
Windows(strWorkbook).Activat
Range("C2").End(xlToRight).Selec
intNbColToDo = ActiveCell.Colum
Range("C3").Selec
ActiveCell.Offset(0, 1).Selec
intNoCol = ActiveCell.Colum
Do While intNoCol < intNbColToD
Set strValidation = ActiveCell.Validatio
On Error GoTo NextCel
With strValidatio
strType = .Typ
strAlertStyle = .AlertStyl
strOperator = .Operato
strFormula1 = .Formula
strFormula2 = .Formula
strValue = .Valu
End Wit
' Return the letter(s) corresponding to th
' column number
strLetter = NbEnAA.NbEnAA(intNoCol
' Write the information
Windows("Utility.xls").Activat
ActiveCell.Value = " Col. " & strLette
ActiveCell.Offset(0, 1).Selec
ActiveCell.Value = strTyp
ActiveCell.Offset(0, 1).Selec
ActiveCell.Value = strAlertStyl
ActiveCell.Offset(0, 1).Selec
ActiveCell.Value = strOperato
ActiveCell.Offset(0, 1).Selec
ActiveCell.Value = strFormula
ActiveCell.Offset(1, -4).Selec
NextCell
Windows(strWorkbook).Activat
ActiveCell.Offset(0, 1).Selec
intNoCol = ActiveCell.Colum
Loo
Windows(strWorkbook).Activat
Next int
Windows("Utility.xls").Activat
MsgBox "Job done.
Exit Su
ErrUtilityWorksheet
Err =
MsgBox "The workbook 'Utility.xls' must be open " &
vbCrLf & vbCrLf & "and the workbook to be treated " &
"must be active.
End Su
'******************************************************************
Thank you.
I'm trying to list some information on validations that are present in some columns of a workbook (with 24 worksheets). I will eventually have to reconstruct these validations on other workbooks
There are 2 types of validations. Either: 1- a list of values that gets its data from a named range and 2- a text length validation of the type "<= 5 characters"
I want to know how to skip a cell that do not contain a validation. The code I wrote gives an error and stops
I also want to distinguish between a validation that shows a list of values and a text length validation (the information to gather is different)
Where can I get the constant names and corresponding numbers (Type property xlValidateTextLength = 6, Operator xlLessEqual = 8, etc.)
Here is some of my code
'******************************************************************
Sub ListValidations(
Dim intNbSheets As Intege
Dim strWorkbook As Strin
Dim intI As Intege
Dim strSheetName As Strin
Dim intNoCol As Intege
Dim intNbColToDo As Intege
Dim strLetter As Strin
Dim strAddresse As Strin
Dim strValidation As Validatio
Dim strType As Strin
Dim strAlertStyle As Strin
Dim strOperator As Strin
Dim strFormula1 As Strin
Dim strFormula2 As Strin
Dim strValue As Strin
strWorkbook = ActiveWorkbook.Nam
intNbSheets = ActiveWorkbook.Sheets.Coun
' Activate utility worksheet
On Error GoTo ErrUtilityWorkshee
Windows("Utility.xls").Activat
Sheets("Lists of values").Activat
Range("A2:B20").Selec
Range("A2").Activat
Selection.Clea
Range("A2").Selec
Range("A2").Value = strWorkboo
Selection.Font.Bold = Tru
Range("A3").Selec
Windows(strWorkbook).Activat
For intI = 1 To intNbSheets -
Workbooks(strWorkbook).Sheets(intI).Activat
strSheetName = ActiveWorkbook.Sheets(intI).Nam
Windows("Utility.xls").Activat
ActiveCell.Value = "Sheet no " & int
Selection.Font.Bold = Tru
ActiveCell.Offset(0, 1).Selec
ActiveCell.Value = strSheetNam
Selection.Font.Bold = Tru
ActiveCell.Offset(1, -1).Selec
' Find out the number of columns to do
Windows(strWorkbook).Activat
Range("C2").End(xlToRight).Selec
intNbColToDo = ActiveCell.Colum
Range("C3").Selec
ActiveCell.Offset(0, 1).Selec
intNoCol = ActiveCell.Colum
Do While intNoCol < intNbColToD
Set strValidation = ActiveCell.Validatio
On Error GoTo NextCel
With strValidatio
strType = .Typ
strAlertStyle = .AlertStyl
strOperator = .Operato
strFormula1 = .Formula
strFormula2 = .Formula
strValue = .Valu
End Wit
' Return the letter(s) corresponding to th
' column number
strLetter = NbEnAA.NbEnAA(intNoCol
' Write the information
Windows("Utility.xls").Activat
ActiveCell.Value = " Col. " & strLette
ActiveCell.Offset(0, 1).Selec
ActiveCell.Value = strTyp
ActiveCell.Offset(0, 1).Selec
ActiveCell.Value = strAlertStyl
ActiveCell.Offset(0, 1).Selec
ActiveCell.Value = strOperato
ActiveCell.Offset(0, 1).Selec
ActiveCell.Value = strFormula
ActiveCell.Offset(1, -4).Selec
NextCell
Windows(strWorkbook).Activat
ActiveCell.Offset(0, 1).Selec
intNoCol = ActiveCell.Colum
Loo
Windows(strWorkbook).Activat
Next int
Windows("Utility.xls").Activat
MsgBox "Job done.
Exit Su
ErrUtilityWorksheet
Err =
MsgBox "The workbook 'Utility.xls' must be open " &
vbCrLf & vbCrLf & "and the workbook to be treated " &
"must be active.
End Su
'******************************************************************
Thank you.