1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| Global WB As Workbook
Global MyMainSheet As Worksheet
'/// Global i, j, cmpti, cmptj As Integer 'Pas bon : seul cmptj est Integer (toutes les autres variables sont Variant)
Sub AjoutValeurs()
Dim TabRNG As Variant
Dim MytabCons() As String
Dim MytabVoy() As String
Dim i As Integer
Dim j As Integer
Dim cmptCons As Integer
Dim cmptVoy As Integer
'/// NON : ThisWorkbook est un mot réservé qui référence le classeur contenant la macro ///
''''Set ThisWorkbook = ActiveWorkbook 'Pas bon
Set WB = ActiveWorkbook
'//////////////////////////////////////////////////////////////////////////////////////////
Set MyMainSheet = WB.Worksheets("Sheet1")
MyMainSheet.Select 'pas utile
TabRNG = MyMainSheet.Range(MyMainSheet.Cells(3, 2), MyMainSheet.Cells(3, 2).End(xlDown)) 'plage B3 : B28 (1 seule colonne donc)
'---
For i = 1 To UBound(TabRNG, 1)
For j = 1 To 1
If Not EstConsonne(TabRNG(i, j)) Then
cmptCons = cmptCons + 1
ReDim Preserve MytabCons(1 To 1, 1 To cmptCons)
MytabCons(1, cmptCons) = TabRNG(i, j)
Else
cmptVoy = cmptVoy + 1
ReDim Preserve MytabVoy(1 To 1, 1 To cmptVoy)
MytabVoy(1, cmptVoy) = TabRNG(i, j)
End If
Next j
Next i
MyMainSheet.Range(Cells(3, 4), Cells(cmptCons + 2, 4)) = Application.WorksheetFunction.Transpose(MytabCons)
MyMainSheet.Range(Cells(3, 5), Cells(cmptVoy + 2, 5)) = Application.WorksheetFunction.Transpose(MytabVoy)
End Sub
Function EstConsonne(ByVal MotTest As String) As Boolean
Dim motConsonne As String
Dim motVoyelle As String
Dim Voyelles As Variant
Dim i&
Voyelles = Array("a", "e", "i", "o", "u")
For i& = LBound(Voyelles) To UBound(Voyelles)
If Left(Trim(MotTest), 1) = Voyelles(i&) Or Left(Trim(MotTest), 1) = UCase(Voyelles(i&)) Then
EstConsonne = True
Exit For
End If
Next i&
End Function |
Partager