EXCEL TOOLS
Excel Add-ins ที่พัฒนาโดยคุณสันติพงศ์ ณสุย (MVP Excel 2010-2020) ด้วยภาษา C# เพื่อแก้ไขปัญหาไฟล์ใหญ่ คำนวณนาน ทำงานช้า จัดการข้อมูลต่าง ๆ ที่ทำงานประจำวันได้อย่างสะดวกรวดเร็ว สนใจคลิกไปดูได้ที่นี่ครับ => Excel Tools
Excel Add-ins ที่พัฒนาโดยคุณสันติพงศ์ ณสุย (MVP Excel 2010-2020) ด้วยภาษา C# เพื่อแก้ไขปัญหาไฟล์ใหญ่ คำนวณนาน ทำงานช้า จัดการข้อมูลต่าง ๆ ที่ทำงานประจำวันได้อย่างสะดวกรวดเร็ว สนใจคลิกไปดูได้ที่นี่ครับ => Excel Tools
[code]
และปิดด้วย [/code]
ตัวอย่างเช่น [code]dim r as range[/code]
เพื่อให้แตกต่างจากข้อความทั่วไป สะดวกในการอ่านและทดสอบ (คลิกเพื่อดูตัวอย่าง).Clear
เพื่อเอาค่าอื่นมาใส่ หากไม่มีการกำหนดรูปแบบไว้ เลขนั้นจะกลายเป็นวันที่=Format(.......,"รูปแบบเลขที่ต้องการ")
.Numberformat="รูปแบบเลขที่ต้องการ"
#,##0.00
ผลที่แสดงออกมากลับเป็นเลขทศนิยมธรรมดา ไม่มีเครื่องหมาย ,
เป็นต้นFormat
ใช้กับ Data type ทุกประเภทไม่ใช่เฉพาะตัวเลข ส่วน .NumberFormat
ใช้กับ Number เท่านั้นครับFormat
หน่อยครับSheet 5 (Pro)
ชื่อ Private Sub Worksheet_Change(ByVal Target As Range)
ครับ (บรรทัดที่ 91)Code: Select all
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rw As Integer
Dim lRw As Long
Dim pcsPck As Integer
Dim pcsPrz As Single, pckPrz As Single, sOld As Single
Dim marG1 As Single, marG2 As Single, marG3 As Single
rw = Target.Row
marG1 = ActiveSheet.Range("l2").Value
marG2 = ActiveSheet.Range("m2").Value
marG3 = ActiveSheet.Range("n2").Value
'//if superuser input pack price in column J
If Target.Column = 10 Then
pckPrz = Target.Value
'//check pieces per pack
If ActiveSheet.Cells(rw, "f").Value <= 0 Then
MsgBox "â»Ã´ãÊè¨Ó¹Ç¹ªÔé¹µèÍá¾é¤¡è͹", vbCritical
Exit Sub
End If
With Application
.ScreenUpdating = False
.EnableEvents = False
.Calculation = xlCalculationManual
End With
With ActiveSheet
.Unprotect
sOld = .Cells(rw, "i").Value
.Cells(rw, "i").Value = Format(Round(pckPrz * (1 + marG2) / _
(1 + marG3) + 0.00001, 0), "#,##0")
.Cells(rw, "h").Value = Format(Round(pckPrz * (1 + marG1) / _
(1 + marG3) + 0.00001, 0), "#,##0")
.Cells(rw, "g").Value = Format(Round(pckPrz / (1 + marG3) + 0.00001, 2), "#,##0")
.Cells(rw, "e").Value = Format(Round(.Cells(rw, "g").Value / .Cells(rw, "f").Value + 0.00001, 2), "#,##0.00")
.Protect
.EnableSelection = xlUnlockedCells
End With
With Sheets("memo")
.Unprotect
lRw = .Range("a" & Rows.Count).End(xlUp).Offset(1, 0).Row
.Cells(lRw, "a") = Format(ActiveSheet.Cells(rw, "b"), "0")
.Cells(lRw, "b") = Format(Now(), "dd/mm/yy hh:mm")
.Cells(lRw, "c") = Format(Round(sOld * (1 + marG3) / (1 + marG2) + 0.00001, 0), "#,##0")
.Cells(lRw, "d") = Format(Target.Value, "#,##0")
.Protect , AllowFiltering:=True
End With
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End If
End Sub
DhitiBank wrote: รหัสเปิดไฟล์คือ adMin (M ตัวใหญ่ครับ)
รหัสเข้าแก้ไข VBA คือ rklg;biNf (keyboard layout เลือกอังกฤษ แล้วพิมพ์ตามแป้นไทยว่า "พาสเวิร์ด")
.NumberFormat
แล้วสังเกตผลลัพธ์ดูใหม่ครับ