ระบายสี Grand Total ทุกครั้งเมื่อจบชื่อ family
Posted: Wed Feb 19, 2014 9:46 am
จะให้ชื่อ "Grand total 2.5" กับ"Grand total 3.5" ระบายสีเหมือน "Grand Total" ทำไงดีค่ะ
แนบไฟล์คู่กับโค้ดไม่ได้ค่ะไฟล์ใหญ่เกินไป รบกวนผู้รู้ช่วยตอบทีน่ะค่ะ ขอบคุณค่ะ
แนบไฟล์คู่กับโค้ดไม่ได้ค่ะไฟล์ใหญ่เกินไป รบกวนผู้รู้ช่วยตอบทีน่ะค่ะ ขอบคุณค่ะ
Code: Select all
Public Sub compareprocap() 'refferenccompare
Application.ScreenUpdating = False
ActiveWorkbook.Sheets("MPS COMPARE").Activate
Dim rAll As Range, r As Range
Dim colR As Collection, item As Variant
Dim subTotal As Double, target As Range
Dim iMax As Integer, icount As Integer
Set colR = New Collection
Dim grandTotal As Double
Dim grand2 As Double
Dim grand3 As Double
grandTotal = 0
With Sheets("NEWDATA")
Set rAll = .Range("a2", .Range("a" & Rows.Count).End(xlUp))
End With
On Error Resume Next
For Each r In rAll
colR.Add r, r 'row number null
Next r
On Error GoTo 0 'debug error
For Each item In colR
iMax = Application.CountIf(rAll, item)
icount = 0
subTotal = 0
For Each r In rAll
If r <> "" Then
With Sheets("MPS COMPARE")
Set target = .Range("a" & Range("a99999").End(xlUp).Row).Offset(1, 0) 'set target
End With
If r = item Then
Rows(target.Row).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromRightOrBelow 'insert row
target.Offset(-1, 0) = r
target.Offset(-1, 0).Offset(0, 1) = r.Offset(0, 1) 'count colum capacity
target.Offset(-1, 0).Offset(0, 1).Font.Bold = True
target.Offset(-1, 0).Offset(0, 1).Offset(0, 1) = r.Offset(0, 1).Offset(0, 1) 'form_fac
Cells(6, 3) = "FORM_FACTOR"
subTotal = subTotal + r.Offset(0, 1)
icount = icount + 1
End If
If icount = iMax Then
Rows(target.Row).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromRightOrBelow 'insert row
With Sheets("MPS COMPARE").Range("a" & Range("a99999").End(xlUp).Row)
.Offset(1, 0) = r + " Total"
.Offset(1, 0).Font.Bold = True
.Offset(1, 1).Font.Color = -10477568
.Offset(1, 1).Font.Bold = True
grandTotal = grandTotal
subTotal = 0
End With
With Sheets("MPS COMPARE")
Range("a" & target.Row - 1 & ":e" & target.Row - 1).Interior.Color = 13434777 'format paint
End With
Exit For
Else
End If
End If
Next r
grandTotal = grandTotal
Next item
With Sheets("MPS COMPARE").Range("a" & Rows.Count).End(xlUp)
.Offset(1, 0) = "Grand Total"
.Offset(1, 0).Font.Bold = True
.Offset(1, 1).Font.Color = 15773696
.Offset(1, 1).Font.Bold = True
.Offset(1, 0).Offset(1, 0) = "Grand Total 2.5"
.Offset(1, 0).Offset(1, 0).Font.Bold = True
.Offset(1, 0).Offset(1, 0).Offset(1, 0) = "Grand Total 3.5"
.Offset(1, 0).Offset(1, 0).Offset(1, 0).Font.Bold = True
End With
With Sheets("MPS COMPARE")
Range("a" & target.Row & ":e" & target.Row).Interior.Color = 49407
End With
Columns("C:C").Select
Selection.NumberFormat = "0.0;[Red]0.0"
Application.ScreenUpdating = True
End Sub