By คุณรีโมเดล ในวันพฤหัสบดีที่ 05 มกราคม 2023
โพสต์ใน Excel
ตอบกลับ 1
การกดไลค์ 0
เข้าชม 3.7K
โหวต 0
ขอขอบคุณล่วงหน้าสำหรับความช่วยเหลือเกี่ยวกับเรื่องนี้ที่คุณสามารถนำเสนอได้

ด้วยความช่วยเหลือของไซต์นี้ ฉันได้สร้างฟังก์ชันต่อไปนี้

ฟังก์ชัน ColorFunction (rColor As Range, rRange As Range, SUM เสริมเป็น Boolean)
Dim rCell เป็นช่วง
ติ่มซำตราบนานเท่านาน
หรี่ vResult
lCol = rColor.Interior.ColorIndex
ถ้า SUM = True แล้ว
สำหรับแต่ละ rCell ใน rRange
ถ้า rCell.Interior.ColorIndex = lCol แล้ว
vResult = WorksheetFunction.SUM(rCell, vResult)
End If
rCell ถัดไป
อื่น
สำหรับแต่ละ rCell ใน rRange
ถ้า rCell.Interior.ColorIndex = lCol แล้ว
vResult = 1 + vผลลัพธ์
End If
rCell ถัดไป
End If
ColorFunction = vResult
ฟังก์ชั่นเอนด์


ในแต่ละเซลล์เป้าหมายที่ฉันต้องการผลรวมของเซลล์ทั้งหมดในแถวนั้นที่มีสีของเซลล์ที่ระบุ
=ฟังก์ชันสี(AR4,H5:AP5,TRUE)

ฉันจะทำให้การขายเป้าหมายอัปเดตได้อย่างไรเมื่อเซลล์อื่นในแถว (H5:AP5) เปลี่ยนสี
สวัสดี,

คุณสามารถเพิ่มรหัส: Application.Calculation = xlอัตโนมัติ เพื่อทำหน้าที่ของคุณ:

Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As Boolean)
Dim rCell As Range
Dim lCol As Long
Dim vResult
Application.Calculation = xlAutomatic
lCol = rColor.Interior.ColorIndex
If SUM = True Then
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = WorksheetFunction.SUM(rCell, vResult)
End If
Next rCell
Else
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = 1 + vResult
End If
Next rCell
End If
ColorFunction = vResult
End Function


กรุณาให้มันลอง

อแมนดา
·
1 ปีที่ผ่านมา
·
0 ชอบ
·
0 คะแนน
·
0 คอมเมนต์
·
ดูโพสต์แบบเต็ม