Page 1 of 1

Calcutation formula เฉพาะ sheet โดยใช้ VBA

Posted: Thu Nov 02, 2023 11:20 am
by Phineas
Calcutation formula เฉพาะ sheet โดยใช้ VBA
อยากคลิก CommandButton_Click() Calcutation formula เฉพาะ sheet

Re: Calcutation formula เฉพาะ sheet โดยใช้ VBA

Posted: Thu Nov 02, 2023 1:40 pm
by snasui
:D การใช้งาน VBA ให้ลองเขียนมาเองก่อนตามกฎการใช้บอร์ดข้อ 4, 5 ด้านบน ติดตรงไหนค่อยถามกันต่อครับ :roll:

Re: Calcutation formula เฉพาะ sheet โดยใช้ VBA

Posted: Thu Nov 02, 2023 4:02 pm
by Phineas

Code: Select all

Private Sub CommandButton2_Click()
    Dim countResult As Long
    Dim ws As Worksheet
    Dim criteriaValue1 As Variant
    Dim criteriaValue2 As Variant
    Dim criteriaValue3 As Variant

    Set ws = ThisWorkbook.Sheets("Record") ' Change "Record" to the name of your specific sheet

    criteriaValue1 = Worksheets("Summary").Range("C2").Value
    criteriaValue2 = ">=" & Worksheets("Summary").Range("E1").Value
    criteriaValue3 = "<" & Worksheets("Summary").Range("F1").Value

    countResult = Application.WorksheetFunction.CountIfs(ws.Range("F:F"), criteriaValue1, ws.Range("C:C"), criteriaValue2, ws.Range("C:C"), criteriaValue3)

    ' Write the countResult to cell E2 in the "Summary" worksheet
    Worksheets("Summary").Range("E2").Value = countResult
End Sub
อยากคำนวณ Write the countResult E2 ถ้า criteriaValue1 C2 ตรงกัน คล้ายๆกด ลากสูตร ให้ excel

Re: Calcutation formula เฉพาะ sheet โดยใช้ VBA

Posted: Thu Nov 02, 2023 4:40 pm
by snasui
:D กรุณาแนบไฟล์ตัวอย่าง พร้อมแสดงตัวอย่างคำตอบที่ต้องการ จะได้สะดวกในการทำความเข้าใจของเพื่อนสมาชิกครับ