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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
| Sub testtab()
Dim xlapp As Excel.Application
Dim xlWbk As Excel.Workbook
Dim xlWsh As Worksheet, xlWsh2 As Excel.Worksheet
Dim Path As String, PathSave As String
Dim Ndossier As String, Nfichier As String, Nsheet As String, NivSeg As String, QLoc As String
Dim Beginline As Integer, Endline As Integer, NumTab As Integer
Dim FirstCol As Integer, LastCol As Integer, FirstCel As Integer, LastCel As Integer, TabCel As Integer
Dim AVGeng As Integer
Dim mycel As Excel.Range
Dim SheetNum As Byte
Dim Nmin As Integer
Set xlapp = CreateObject("Excel.Application")
xlapp.DisplayAlerts = False
With Sheets("Liste_Tables")
Beginline = 2
If Range("A" & Beginline).Offset(1, 0).Value <> "" Then
Endline = Range("A" & Beginline).End(xlDown).Row
Else
Endline = Beginline
End If
'Loop Nbre de fichiers
For NumTab = Beginline To Endline
Ndossier = Range("A" & NumTab).Value
Nfichier = Range("B" & NumTab).Value
NivSeg = Range("C" & NumTab).Value
QLoc = Range("D" & NumTab).Value
Path = Ndossier & "TB_Export\" & Nfichier & ".xlsx"
PathSave = Ndossier & "TB_Layout\RP Survey_" & Nfichier & " 2013.xlsx"
Set xlWbk = xlapp.Workbooks.Open(Path)
xlapp.Visible = True
'Loop Sheets
For SheetNum = 1 To xlapp.Sheets.Count
Set xlWsh = xlWbk.Worksheets(SheetNum)
With xlWsh
.Rows("1:4").Delete
.Columns("B:B").Delete
FirstCol = 1
LastCol = .Cells(NivSeg + 1, FirstCol).End(xlToRight).Column
LastCel = .Range("A65536").End(xlUp).Row
With .Rows("1:65536")
With .Font
.Name = "Tahoma"
.Size = 8
.Bold = False
.Italic = False
.Color = RGB(97, 96, 101)
End With
With .Cells
.VerticalAlignment = xlCenter
.HorizontalAlignment = xlCenter
End With
End With
With .Columns("A:A").Cells
.HorizontalAlignment = xlLeft
End With
.Rows(NivSeg + 2 & ":" & NivSeg + 3).Font.Bold = True
.Rows(NivSeg + 8 & ":" & NivSeg + 8).Font.Bold = True
If QLoc = "Y" Then
.Rows(NivSeg + 16 & ":" & NivSeg + 16).Font.Bold = True
End If
'Cadre
With .Range(.Cells(1, 1), .Cells(LastCel, LastCol)).Borders
.LineStyle = xlContinuous
.Weight = xlThin
.Color = RGB(79, 129, 189)
End With
'Format Columns & Rows
.Columns("A:A").WrapText = False
.Columns.ColumnWidth = 10
.Columns("A:A").EntireColumn.AutoFit
.Rows("1:" & LastCel + 4).Rows.RowHeight = 10.5
.Rows("1:" & NivSeg).EntireRow.AutoFit
'Moyenne pondérée (Overall engagement)
For AVGeng = 2 To LastCol
.Cells(5, AVGeng).Value = .Cells(6, AVGeng).Value * 0.14 + _
.Cells(7, AVGeng).Value * 0.26 + _
.Cells(8, AVGeng).Value * 0.14 + _
.Cells(9, AVGeng).Value * 0.46
Next AVGeng
'Couleurs cellules
For Each mycel In .Range(.Cells(NivSeg + 2, 2), .Cells(LastCel, LastCol))
If mycel.Value <> "." And mycel.Value <> "99999" And mycel.Value <> "88888" Then
mycel.Value = Round((mycel.Value * 1), 1)
Select Case mycel.Value
Case Is = "": mycel.Interior.Pattern = xlNone
Case Is < 6.5
mycel.Interior.Color = RGB(255, 0, 0)
mycel.Font.Color = RGB(255, 255, 255)
Case 6.5 To 7.4
mycel.Interior.Color = RGB(255, 255, 0)
mycel.Font.Color = RGB(0, 0, 0)
Case Is > 7.4
mycel.Interior.Color = RGB(0, 255, 0)
mycel.Font.Color = RGB(0, 0, 0)
End Select
ElseIf mycel.Value = "99999" Then
Select Case mycel.Value
Case Is = "99999": mycel.Interior.Pattern = xlNone
mycel.Value = ""
End Select
ElseIf mycel.Value = "88888" Then
Select Case mycel.Value
Case Is = "88888": mycel.Interior.Pattern = xlNone
mycel.Value = "NA"
End Select
End If
Next
'Suppression des résultats si n<5
For Nmin = 2 To LastCol
If .Cells(NivSeg + 1, Nmin).Value < 5 Then
.Range(.Cells(NivSeg + 3, Nmin), .Cells(LastCel, Nmin)).Value = "NA"
.Range(.Cells(NivSeg + 8, Nmin), .Cells(NivSeg + 8, Nmin)).Value = ""
.Range(.Cells(NivSeg + 3, Nmin), .Cells(LastCel, Nmin)).Font.Color = RGB(97, 96, 101)
.Range(.Cells(NivSeg + 3, Nmin), .Cells(LastCel, Nmin)).Interior.Color = xlNone
If QLoc = "Y" Then
.Range(.Cells(NivSeg + 16, Nmin), .Cells(NivSeg + 16, Nmin)).Value = ""
End If
End If
Next Nmin
'Légende
With .Range(.Cells(LastCel + 2, 1), .Cells(LastCel + 2, 1))
.Value = "High score >7.4"
With .Font
.Color = RGB(0, 0, 0)
End With
.Interior.Color = RGB(0, 255, 0)
End With
With .Range(.Cells(LastCel + 3, 1), .Cells(LastCel + 3, 1))
.Value = "Medium score 6.5-7.4"
With .Font
.Color = RGB(0, 0, 0)
End With
.Interior.Color = RGB(255, 255, 0)
End With
With .Range(.Cells(LastCel + 4, 1), .Cells(LastCel + 4, 1))
.Value = "Low score <6.5"
With .Font
.Color = RGB(255, 255, 255)
End With
.Interior.Color = RGB(255, 0, 0)
End With
With .Range(.Cells(LastCel + 2, 1), .Cells(LastCel + 4, 1))
With .Borders
.LineStyle = xlContinuous
.Weight = xlThin
.Color = RGB(79, 129, 189)
End With
End With
End With
Next SheetNum
'Copie du fichier tableau spss
xlWbk.SaveCopyAs (PathSave)
xlWbk.Close SaveChanges:=False
Next
End With
xlapp.DisplayAlerts = True
End Sub |
Partager