:D snasui.com ยินดีต้อนรับ :D
ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย :thup: สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ :arrow: ระบุ Version ของ Excel
:!: โปรดทราบ :!:
  1. กรุณาอ่านกฎการใช้บอร์ด (Forum rules) ในตำแหน่งด้านบนของแต่ละบอร์ด
  2. การสมัครสมาชิก การ Login การกู้คืนรหัสผ่าน
    1. สมัครสมาชิกดูขั้นตอนได้ที่ :arrow: สมัครสมาชิก
    2. Login เข้าระบบโดยคลิกปุ่ม Login ตรงมุมขวาบนของหน้านี้ :roll:
    3. การ Login ผ่าน Facebook ดูวิธีที่ :arrow: Login ผ่าน Facebook
    4. ลืมรหัสผ่านสามารถรับรหัสใหม่ได้ที่ :arrow: Reset รหัสผ่าน
  3. มีปัญหาการใช้งาน แจ้งผู้ดูแลระบบได้ที่ :arrow: ติดต่อผู้ดูแลระบบ
  4. กำหนดการตั้งค่าส่วนตัว เช่นตั้งค่าภาษาเป็นไทยหรืออังกฤษดูได้ที่ :arrow: ตั้งค่าส่วนตัว
  5. การตั้งและตอบกระทู้ดูได้ที่ :arrow: วิธีการตั้งและตอบกระทู้
  6. การจัดรูปแบบตัวอักษรด้วย bbcode ในช่องแสดงความคิดเห็นดูได้ที่ :arrow: จัดรูปแบบตัวอักษร
  7. กำหนดขนาดตัวอักษรใน Browser ดูได้ที่ :arrow: กำหนดขนาดตัวอักษรใน Browser

วิธีจัดทำรายงานสรุปใบเสร็จรับเงิน แบบ LINK สูตร

ฟอรัมถาม-ตอบปัญหาการใช้งานสูตรและฟังก์ชัน Excel
Forum rules
  1. ไม่อนุญาตให้ใช้ภาษาแชทในการถามและตอบปัญหา ไม่ใช้คำว่า "คับ" หรือ "อ่ะครับ" แทนคำว่า "ครับ" ไม่ใช้คำว่า "เด๋ว" แทนคำว่า "เดี๋ยว" เป็นต้น เนื่องจากเมื่อแปลเป็นภาษาต่างประเทศแล้วจะให้ความหมายผิดไปจากที่ควรจะเป็น
  2. ห้ามถามโดยระบุชื่อผู้ตอบและต้องตั้งชื่อกระทู้ให้สื่อถึงปัญหาที่จะถาม ไม่ตั้งชื่อว่า ช่วยด้วยครับ, มีปัญหามาปรึกษาครับ เป็นต้น
  3. กรุณาอธิบายปัญหาและระบุคำตอบที่ต้องการมาในกระทู้ด้วยเสมอถึงแม้จะอธิบายไว้ในไฟล์แนบแล้วก็ตาม ทั้งนี้เพื่ออำนวยความสะดวกแก่เพื่อนสมาชิกในการค้นหาข้อมูล
  4. กรุณาแนบไฟล์ตัวอย่างพร้อมแสดงคำตอบที่ถูกต้องมาในไฟล์ด้วยเพื่อให้ง่ายต่อการทำความเข้าใจและสะดวกต่อการตอบคำถาม (ขนาดไฟล์ไม่เกิน 500Kb ขนาดภาพไม่เกิน 800*600 Pixel) ไม่แนบเป็น Link มาจากแหล่งอื่นที่อาจจะถูกลบทิ้งไปโดยต้นทางในภายหลัง นอกจากนี้ไม่ควรแนบไฟล์ที่มีข้อมูลสำคัญอันก่อให้เกิดความเสียหายกับตนเองและผู้อื่น
  5. กรณีเป็นคำถามเกี่ยวกับ Programming เช่น VBA, VB.Net, C#, SQL ฯลฯ ต้องลองเขียนมาเองก่อนเสมอ ถามเฉพาะที่ติดปัญหา ระบุ Module, Procedure ที่ติดปัญหาให้ชัดเจน กรุณาโพสต์ Code ให้แสดงเป็น Code คือเปิดด้วย [code] และปิดด้วย [/code] ตัวอย่างเช่น [code]dim r as range[/code] เพื่อให้แตกต่างจากข้อความทั่วไป สะดวกในการอ่านและทดสอบ (คลิกเพื่อดูตัวอย่าง)
  6. กรุณาแจ้งผลการใช้งานเมื่อได้รับคำตอบว่าตรงกับความต้องการหรือไม่
annier_cute_1171986
Member
Member
Posts: 6
Joined: Wed Jan 07, 2015 4:35 pm

วิธีจัดทำรายงานสรุปใบเสร็จรับเงิน แบบ LINK สูตร

#1

Post by annier_cute_1171986 »

ในแต่ละเดือน เรามีออกใบเสร็จรับเงินให้กับลูกค้าประมาณเดือนละ 200 ใบ ซึ่งเราต้อง COPY PASTE แต่ละใบเสร็จมาจัดทำ "รายงานสรุปใบเสร็จรับเงิน"

เอง ทำให้ใช้เวลาทำนานมาก ใน Excel มีสูตรไหนในการดึงรายละเอียดมาเป็นรายงานแบบทั้งเดือน กับ สรุปเป็นรายวันบ้างคะ แล้วต้องเขียนสูตรยังไงคะ
You do not have the required permissions to view the files attached to this post.
User avatar
snasui
Site Admin
Site Admin
Posts: 31257
Joined: Sun Jan 24, 2010 12:33 pm
Location: Songkhla, Thailand
Excel Ver: 2010, 2019
Contact:

Re: วิธีจัดทำรายงานสรุปใบเสร็จรับเงิน แบบ LINK สูตร

#2

Post by snasui »

:D ควรอธิบายมาว่าข้อมูลต้นทางคือชีทใด ข้อมูลปลายทางคือชีทใด ตัวอย่างคำตอบที่ต้องการเป็นอย่างไร จะได้สะดวกในการทำความเข้าใจของเพื่อน ๆ ครับ
annier_cute_1171986
Member
Member
Posts: 6
Joined: Wed Jan 07, 2015 4:35 pm

Re: วิธีจัดทำรายงานสรุปใบเสร็จรับเงิน แบบ LINK สูตร

#3

Post by annier_cute_1171986 »

ข้อมูลต้นทาง คือ Sheet 1 , 2 , 3 เป็นใบเสร็จรับเงินของทั้งเดือน ซึ่งแบบฟอร์มจะเหมือนกัน และ

ข้อมูลปลายทาง เป็น 1) สรุปรายงานใบเสร็จรับเงินทั้งเดือน มีรายละเอียดของทุกใบเสร็จรับเงิน

2) สรุปรายงานใบเสร็จรับเงินแยกเป็นวันๆ มียอดรวมที่เป็นจำนวนเงินในแต่ละวัน
User avatar
snasui
Site Admin
Site Admin
Posts: 31257
Joined: Sun Jan 24, 2010 12:33 pm
Location: Songkhla, Thailand
Excel Ver: 2010, 2019
Contact:

Re: วิธีจัดทำรายงานสรุปใบเสร็จรับเงิน แบบ LINK สูตร

#4

Post by snasui »

:D ลักษณะของงานนี้ควรใช้ VBA เข้ามาจัดการ โดยทำแบบฟอร์มใบเสร็จขึ้นมาเพียงชีทเดียว มีปุ่มสำหรับการจัดเก็บข้อมูลลง Database

การทำรายงานก็จะนำข้อมูลจาก Database มาทำ ไม่ใช่นำมาจากชีทรายวันมาทำครับ

สำหรับการใช้ VBA จำเป็นต้องเขียนมาเองก่อนตามกฎการใช้บอร์ดข้อ 5 ด้านบน :roll: ติดตรงไหนค่อยถามกันต่อ
wichaipr
Member
Member
Posts: 1
Joined: Tue Dec 25, 2012 9:31 pm

Re: วิธีจัดทำรายงานสรุปใบเสร็จรับเงิน แบบ LINK สูตร

#5

Post by wichaipr »

สรุปใบเสร็จรับเงิน
You do not have the required permissions to view the files attached to this post.
User avatar
bank9597
Guru
Guru
Posts: 3868
Joined: Wed Aug 17, 2011 11:49 am

Re: วิธีจัดทำรายงานสรุปใบเสร็จรับเงิน แบบ LINK สูตร

#6

Post by bank9597 »

:) ทีนี้ก็อธิบายครับว่า ในไฟล์ที่แนบมานั้น มีส่วนไหนเป็นฐษนข้อมูล ส่วนไหนเป็นฟอร์ม ระบุชื่อชีทให้ชัดเจน พร้อมโค๊ดที่เขียนมาแล้วยังติดปัญหาอยู่นั้น คือโค๊ดใด
Forum Rules
  1. อย่าใช้ภาษาแชทในการตอบ-ถาม
  2. ตั้งชื่อกระทู้ให้สื่อถึงปัญหาและไม่เจาะจงตัวผู้ตอบ
  3. ให้อธิบายปัญหาและระบุคำตอบที่ต้องการมาในฟอรัม
  4. ควรแนบไฟล์ตัวอย่างมาที่ฟอรั่ม
  5. หากใช้ VBA ให้ลองเขียนมาเองก่อนเสมอ
  6. แจ้งผลการใช้งานทุกครั้งเมื่อได้รับคำตอบ
sirthun
Member
Member
Posts: 9
Joined: Fri Jul 21, 2017 4:19 pm

Re: วิธีจัดทำรายงานสรุปใบเสร็จรับเงิน แบบ LINK สูตร

#7

Post by sirthun »

snasui wrote::D ลักษณะของงานนี้ควรใช้ VBA เข้ามาจัดการ โดยทำแบบฟอร์มใบเสร็จขึ้นมาเพียงชีทเดียว มีปุ่มสำหรับการจัดเก็บข้อมูลลง Database

การทำรายงานก็จะนำข้อมูลจาก Database มาทำ ไม่ใช่นำมาจากชีทรายวันมาทำครับ

สำหรับการใช้ VBA จำเป็นต้องเขียนมาเองก่อนตามกฎการใช้บอร์ดข้อ 5 ด้านบน :roll: ติดตรงไหนค่อยถามกันต่อ
ถ้าตามกรณีนี้ จะเขียนโค้ดให้นำข้อมูลจากตาราง(ในSheet 1-21) มาลงในฟอร์ม(Sheet Daily และ Monthly) ในลักษณะไหนครับ โดยอ้างอิงจากชื่อหรือรหัสพนักงาน และวันที่ครับ โดยแยกเป็นรายบุคคล ฟอร์มในชีทSheet Daily เป็นวันเดียว ส่วน ฟอร์มในชีท Mouthly เป็นรวมทั้งเดือนครับ รบกวนอาจารย์ชี้แนะด้วยครับ
You do not have the required permissions to view the files attached to this post.
User avatar
logic
Gold
Gold
Posts: 1511
Joined: Thu Mar 18, 2010 1:57 pm
Excel Ver: 365

Re: วิธีจัดทำรายงานสรุปใบเสร็จรับเงิน แบบ LINK สูตร

#8

Post by logic »

ลองกรอกตัวอย่างคำตอบด้วยมือและแนบมาด้วยครับ จะได้เห็นว่าคำตอบเป็นแบบไหน เพื่อน ๆ จะได้ช่วยกันคิดต่อได้ครับ :)
sirthun
Member
Member
Posts: 9
Joined: Fri Jul 21, 2017 4:19 pm

Re: วิธีจัดทำรายงานสรุปใบเสร็จรับเงิน แบบ LINK สูตร

#9

Post by sirthun »

จากไฟล์แนบของผม ผมได้สร้างUserForm สำหรับเพิ่มข้อมูลลงตารางไว้แล้วครับ แต่ตอนนี้ยังคิดไม่ออกเลยว่าจะเอาข้อมูลไปลงในแบบฟอร์มที่ทำไว้ยังไง(worksheet Monthly,Daily) รบกวนชี้แนะผมด้วยครับ
User avatar
snasui
Site Admin
Site Admin
Posts: 31257
Joined: Sun Jan 24, 2010 12:33 pm
Location: Songkhla, Thailand
Excel Ver: 2010, 2019
Contact:

Re: วิธีจัดทำรายงานสรุปใบเสร็จรับเงิน แบบ LINK สูตร

#10

Post by snasui »

:D เอาข้อมูลไปลงในตารางสามารถใช้การ Loop แต่ละเซลล์แต่ละชีตเพื่อนำค่ามาวางได้ แต่จะต้องทราบเสียก่อนว่าต้องการนำข้อมูลใด ไปไว้ที่ใด ด้วยเงื่อนไขใด คำตอบที่ถูกต้องเป็นอย่างไร คุณ logic ช่วยแจ้งไปแล้วว่าให้ทำตัวอย่างคำตอบที่ถูกต้องมาแสดงด้วยจะได้เข้าใจตรงกัน สะดวกในการตอบครับ
sirthun
Member
Member
Posts: 9
Joined: Fri Jul 21, 2017 4:19 pm

Re: วิธีจัดทำรายงานสรุปใบเสร็จรับเงิน แบบ LINK สูตร

#11

Post by sirthun »

อยู่ในSheet Daily นะครับ สำหรับเงื่อนไข กับเซลล์ที่ลงข้อมูล :D
You do not have the required permissions to view the files attached to this post.
User avatar
snasui
Site Admin
Site Admin
Posts: 31257
Joined: Sun Jan 24, 2010 12:33 pm
Location: Songkhla, Thailand
Excel Ver: 2010, 2019
Contact:

Re: วิธีจัดทำรายงานสรุปใบเสร็จรับเงิน แบบ LINK สูตร

#12

Post by snasui »

:D จากตัวอย่างไฟล์คำตอบ ชีต Daily เซลล์ E5 มีค่า 120 มีวิธีคิดอย่างไรหรือนำอัตรามาจากไหน ช่วยอธิบายเพิ่มให้ครบทุกอัตราครับ :?:
sirthun
Member
Member
Posts: 9
Joined: Fri Jul 21, 2017 4:19 pm

Re: วิธีจัดทำรายงานสรุปใบเสร็จรับเงิน แบบ LINK สูตร

#13

Post by sirthun »

เงื่อนไขค่าเที่ยวนะครับ
จะแบ่งตามประเภทรถ กับระยะทาง แล้วก็จำนวนเที่ยว ในตัวอย่างเป็นรถ 6 ล้อ
กรณีไม่ถึง 400 กม
เท่ี่ยว 1
พนง.ขับ 100 พนง.ติดรถ 20
เที่ยว 2
พนง.ขับ 120 พนง.ติดรถ 50
**แต่ถ้าวันนั้นทั้งวัน วิ่งแค่1เที่ยว จะคิดให้เป็นราคาเดียวกับเที่ยว 2 ครับ**
กรณี เกิน 400 กม.
ทุกเที่ยวราคาเท่ากันหมด
พนง.ขับ 200 พนง.ติดรถ 80
ปล.อยากสอบถามอาจารย์ว่า ถ้ามีเงื่อนไขเกี่ยวกับพวกประเภทรถ ประเภทพนักงาน ต้องเขียนClass รึเปล่าครับ แต่ผมได้สร้างClassไว้แล้วคือส่วนของพนักงาน(Class EmCls แล้วประกาศค่าตัวแปรในModule1) ไม่รู้ว่าทำถูกต้องรึเปล่า รบกวนอาจารย์ช่วยตรวจด้วยครับ แหะๆ :)
User avatar
snasui
Site Admin
Site Admin
Posts: 31257
Joined: Sun Jan 24, 2010 12:33 pm
Location: Songkhla, Thailand
Excel Ver: 2010, 2019
Contact:

Re: วิธีจัดทำรายงานสรุปใบเสร็จรับเงิน แบบ LINK สูตร

#14

Post by snasui »

:D กรณีคำถามเกี่ยวกับ Class ผมเห็นว่าไม่จำเป็นต้องสร้างเป็น Class แต่หากสร้างมาแล้วและใช้งานได้ก็ย่อมจะใช้การได้ครับ

กรณีของการทำรายงานเป็นรายวันและรายเดือน ยังไม่มีการเขียน Code มาแต่อย่างใด ผมจึงตอบเป็นสูตรมาให้ โดยมีวิธีการตามด้านล่าง

ให้เพิ่มชีตมา 1 ชีตสมมุติว่าชื่อ Sheet1 เพื่อนำข้อมูลทั้งหมดมาเรียงต่อกันด้วยสูตรด้านล่าง
  1. K2:K32 คีย์เลข 1-31
  2. L2 คีย์สูตร
    =COUNT(INDIRECT("'"&K2&"'!A:A"))
    Enter > Copy ลงด้านล่างถึง L32
  3. L33 คีย์สูตร
    =SUM(L2:L32)
    Enter
  4. M2 คีย์สูตร=SUM(L$2:L2)-L2+1
    Enter > Copy ลงด้านล่างถึง M32
  5. I2 คีย์สูตร
    =IF(ROWS(I$2:I2)>$L$33,"",LOOKUP(ROWS(I$2:I2),$M$2:$M$32,$K$2:$K$32))
    Enter > Copy ลงด้านล่างจนได้ผลลัพธ์เป็นค่าว่าง
  6. A2 คีย์สูตร
    =IF($I2="","",OFFSET(INDIRECT("'"&$I2&"'!A2"),COUNTIF($I$2:$I2,$I2)-1,COLUMNS($A2:A2)-1))
    Enter > Copy ไปด้านขวาถึง G2 แล้ว Copy ลงด้านล่างจนได้ผลลัพธ์เป็นค่าว่าง
  7. H2 คีย์สูตร
    =IF(I2<>"",A2&B2&C2,"")
    Enter > Copy ลงด้านล่างจนได้ผลลัพธ์เป็นค่าว่าง
ที่ชีต Monthly
  1. A6 คีย์สูตร
    =IFERROR(INDEX(Sheet1!A$2:A$20,SMALL(IF(FREQUENCY(MATCH("~"&Sheet1!$H$2:$H$20,Sheet1!$H$2:$H$20&"",0),ROW(Sheet1!$H$2:$H$20)-ROW(Sheet1!$H$2)+1),ROW(Sheet1!$H$2:$H$20)-ROW(Sheet1!$H$2)+1),ROWS(A$6:A6))),"")
    Ctrl+Shift+Enter > Copy ลงด้านล่าง
  2. B6 คีย์สูตร
    =IFERROR(INDEX(Sheet1!B$2:B$20,SMALL(IF(FREQUENCY(MATCH("~"&Sheet1!$H$2:$H$20,Sheet1!$H$2:$H$20&"",0),ROW(Sheet1!$H$2:$H$20)-ROW(Sheet1!$H$2)+1),ROW(Sheet1!$H$2:$H$20)-ROW(Sheet1!$H$2)+1),ROWS(B$6:B6))),"")
    Ctrl+Shift+Enter > Copy ลงด้านล่าง
  3. C6 คีย์สูตร
    =IFERROR(INDEX(Sheet1!C$2:C$20,SMALL(IF(FREQUENCY(MATCH("~"&Sheet1!$H$2:$H$20,Sheet1!$H$2:$H$20&"",0),ROW(Sheet1!$H$2:$H$20)-ROW(Sheet1!$H$2)+1),ROW(Sheet1!$H$2:$H$20)-ROW(Sheet1!$H$2)+1),ROWS(C$6:C6))),"")
    Ctrl+Shift+Enter > Copy ลงด้านล่าง
  4. D6 คีย์สูตร
    =IFERROR(INDEX(Sheet1!D$2:D$20,SMALL(IF(FREQUENCY(MATCH("~"&Sheet1!$H$2:$H$20,Sheet1!$H$2:$H$20&"",0),ROW(Sheet1!$H$2:$H$20)-ROW(Sheet1!$H$2)+1),ROW(Sheet1!$H$2:$H$20)-ROW(Sheet1!$H$2)+1),ROWS(D$6:D6))),"")
    Ctrl+Shift+Enter > Copy ลงด้านล่าง
  5. M6 คีย์สูตร
    =IFERROR(INDEX(Sheet1!G$2:G$20,SMALL(IF(FREQUENCY(MATCH("~"&Sheet1!$H$2:$H$20,Sheet1!$H$2:$H$20&"",0),ROW(Sheet1!$H$2:$H$20)-ROW(Sheet1!$H$2)+1),ROW(Sheet1!$H$2:$H$20)-ROW(Sheet1!$H$2)+1),ROWS(M$6:M6))),"")
    Ctrl+Shift+Enter > Copy ลงด้านล่าง
  6. J6 คีย์สูตร
    =SUMIFS(Sheet1!$F$2:$F$20,Sheet1!$H$2:$H$20,$A6&$B6&$C6,Sheet1!$E$2:$E$20,RIGHT(J$5))
    Enter > Copy ลงด้านล่าง
  7. K6 คีย์สูตร
    =SUMIFS(Sheet1!$F$2:$F$20,Sheet1!$H$2:$H$20,$A6&$B6&$C6,Sheet1!$E$2:$E$20,RIGHT(K$5))
    Enter > Copy ลงด้านล่าง
  8. L6 คีย์สูตร
    =SUMIFS(Sheet1!$F$2:$F$20,Sheet1!$H$2:$H$20,$A6&$B6&$C6,Sheet1!$E$2:$E$20,RIGHT(L$5))
    Enter > Copy ลงด้านล่าง
ให้ลองนำไปประยุกต์ใช้กับชีตรายวัน ในส่วนของจำนวนเงินค่าเที่ยวเกี่ยวกับประเภทรถ ไม่ทราบว่าดูจากเซลล์ไหน ชีตไหน ว่ารายการปัจจุบันเป็นรถประเภทใด ช่วยแจ้งมาอีกรอบครับ

!
Note: Ctrl+Shift+Enter เป็นการสร้างสูตร Array โดยสามารถเลือกดำเนินการตามข้อ 1 หรือ 2 ด้านล่าง
  1. กรณีคีย์สูตรเอง เมื่อคีย์สูตรแล้ว แทนที่จะกด Enter ให้กดแป้น Ctrl และ Shift พร้อมกันค้างไว้แล้วกด Enter เพื่อสร้างเป็นสูตร Array
  2. กรณี Copy สูตรไปวางให้กดแป้น F2 เพื่อทำการ Edit Cell นั้นก่อน จากนั้นกดแป้น Ctrl และ Shift พร้อมกันค้างไว้แล้วตามด้วย Enter เพื่อสร้างเป็นสูตร Array
  3. หากกดแป้นถูกต้องสูตรนั้นจะมีเครื่องหมายปีกกาครอบ เช่น {=YourFormulas(...)} ปีกกานี้ไม่สามารถคีย์เข้าไปเอง จะต้องมาด้วยการกดแป้น Ctrl+Shift+Enter เท่านั้น ถ้ายังไม่เห็นปีกกาครอบสูตรแสดงว่ากดแป้นให้รับสูตรไม่ถูกต้อง
  4. การแก้ไขเปลี่ยนแปลงสูตร Array จะต้องกดแป้นให้รับสูตรด้วย Ctrl+Shift+Enter ทุกครั้ง
sirthun
Member
Member
Posts: 9
Joined: Fri Jul 21, 2017 4:19 pm

Re: วิธีจัดทำรายงานสรุปใบเสร็จรับเงิน แบบ LINK สูตร

#15

Post by sirthun »

ขอบคุณอาจารย์เรื่องสูตรการlookup ครับ เป็นสูตรที่สุดยอดมากๆครับ
เรื่องการคำนวนค่าเที่ยว ครั้งแรกผมคิดว่าจะใช้สูตรคำนวนในvbเลย โดยคิดจากระยะ ที่ใส่เข้าไปในชีทรายบุคคลของพนักงาน 1-21 ตามเงื่อนไข
กรณีไม่ถึง 400 กม
เท่ี่ยว 1
พนง.ขับ 100 พนง.ติดรถ 20
เที่ยว 2
พนง.ขับ 120 พนง.ติดรถ 50
**แต่ถ้าวันนั้นทั้งวัน วิ่งแค่1เที่ยว จะคิดให้เป็นราคาเดียวกับเที่ยว 2 ครับ**
กรณี เกิน 400 กม.
ทุกเที่ยวราคาเท่ากันหมด
พนง.ขับ 200 พนง.ติดรถ 80
แต่น่าจะทำสูตรคำนวนในชีทง่ายกว่าใช่ไหมครับ
ในส่วนของประเภทรถ ยังไม่ได้ทำครับ แต่เขียนไว้ในClassแล้ว กะว่าจะทำการคำนวนในvbทั้งหมดเลย
ประมาณนี้ได้ไหมครับ

Code: Select all

Sub Calculate()
    With Worksheets("1")
    If Range("F2") <= 399 Then
        Range("H2") = 120
        ElseIf Range("F2") <= 600 Then
            Range("H2") = 200
    End If
    End With
End Sub
ถ้ามีวิธีไหนที่ดีกว่ารบกวนอาจารย์ช่วยชี้แนะด้วยครับ
sirthun
Member
Member
Posts: 9
Joined: Fri Jul 21, 2017 4:19 pm

Re: วิธีจัดทำรายงานสรุปใบเสร็จรับเงิน แบบ LINK สูตร

#16

Post by sirthun »

เพิ่มเติมครับ สำหรับเงื่อนไขคำนวณค่าเที่ยว

Code: Select all

'SizeL
        If UserForm1.ComboBox1.Value = Car1.CarLicen And UserForm1.TextBox2.Value = 1 And UserForm1.TextBox3.Value <= 399 Then
            ws.Cells(i, 7) = range1L
            ElseIf UserForm1.ComboBox1.Value = Car1.CarLicen And UserForm1.TextBox2.Value = 2 And UserForm1.TextBox3.Value <= 399 Then
                ws.Cells(i, 7) = range2L
                ElseIf UserForm1.ComboBox1.Value = Car1.CarLicen And UserForm1.TextBox2.Value = 3 And UserForm1.TextBox3.Value <= 399 Then
                    ws.Cells(i, 7) = range3L
                    ElseIf UserForm1.ComboBox1.Value = Car1.CarLicen And UserForm1.TextBox3.Value <= 600 Then
                        ws.Cells(i, 7) = rangeOver1
                        ElseIf UserForm1.ComboBox1.Value = Car1.CarLicen And UserForm1.TextBox3.Value <= 800 Then
                            ws.Cells(i, 7) = rangeOver2
                            ElseIf UserForm1.ComboBox1.Value = Car1.CarLicen And UserForm1.TextBox3.Value <= 1000 Then
                                ws.Cells(i, 7) = rangeOver3
                                ElseIf UserForm1.ComboBox1.Value = Car1.CarLicen And UserForm1.TextBox3.Value <= 1499 Then
                                    ws.Cells(i, 7) = rangeOver4
                                        ElseIf UserForm1.ComboBox1.Value = Car1.CarLicen And UserForm1.TextBox3.Value >= 1500 Then
                                            ws.Cells(i, 7) = rangeOver5
        End If
        If UserForm1.ComboBox1.Value = Car2.CarLicen And UserForm1.TextBox2.Value = 1 And UserForm1.TextBox3.Value <= 399 Then
            ws.Cells(i, 7) = range1L
            ElseIf UserForm1.ComboBox1.Value = Car2.CarLicen And UserForm1.TextBox2.Value = 2 And UserForm1.TextBox3.Value <= 399 Then
                ws.Cells(i, 7) = range2L
                ElseIf UserForm1.ComboBox1.Value = Car2.CarLicen And UserForm1.TextBox2.Value = 3 And UserForm1.TextBox3.Value <= 399 Then
                    ws.Cells(i, 7) = range3L
                    ElseIf UserForm1.ComboBox1.Value = Car2.CarLicen And UserForm1.TextBox3.Value <= 600 Then
                        ws.Cells(i, 7) = rangeOver1
                        ElseIf UserForm1.ComboBox1.Value = Car2.CarLicen And UserForm1.TextBox3.Value <= 800 Then
                            ws.Cells(i, 7) = rangeOver2
                            ElseIf UserForm1.ComboBox1.Value = Car2.CarLicen And UserForm1.TextBox3.Value <= 1000 Then
                                ws.Cells(i, 7) = rangeOver3
                                ElseIf UserForm1.ComboBox1.Value = Car2.CarLicen And UserForm1.TextBox3.Value <= 1499 Then
                                    ws.Cells(i, 7) = rangeOver4
                                        ElseIf UserForm1.ComboBox1.Value = Car2.CarLicen And UserForm1.TextBox3.Value >= 1500 Then
                                            ws.Cells(i, 7) = rangeOver5
        End If
        If UserForm1.ComboBox1.Value = Car3.CarLicen And UserForm1.TextBox2.Value = 1 And UserForm1.TextBox3.Value <= 399 Then
            ws.Cells(i, 7) = range1L
            ElseIf UserForm1.ComboBox1.Value = Car3.CarLicen And UserForm1.TextBox2.Value = 2 And UserForm1.TextBox3.Value <= 399 Then
                ws.Cells(i, 7) = range2L
                ElseIf UserForm1.ComboBox1.Value = Car3.CarLicen And UserForm1.TextBox2.Value = 3 And UserForm1.TextBox3.Value <= 399 Then
                    ws.Cells(i, 7) = range3L
                    ElseIf UserForm1.ComboBox1.Value = Car3.CarLicen And UserForm1.TextBox3.Value <= 600 Then
                        ws.Cells(i, 7) = rangeOver1
                        ElseIf UserForm1.ComboBox1.Value = Car3.CarLicen And UserForm1.TextBox3.Value <= 800 Then
                            ws.Cells(i, 7) = rangeOver2
                            ElseIf UserForm1.ComboBox1.Value = Car3.CarLicen And UserForm1.TextBox3.Value <= 1000 Then
                                ws.Cells(i, 7) = rangeOver3
                                ElseIf UserForm1.ComboBox1.Value = Car3.CarLicen And UserForm1.TextBox3.Value <= 1499 Then
                                    ws.Cells(i, 7) = rangeOver4
                                        ElseIf UserForm1.ComboBox1.Value = Car3.CarLicen And UserForm1.TextBox3.Value >= 1500 Then
                                            ws.Cells(i, 7) = rangeOver5
        End If
        If UserForm1.ComboBox1.Value = Car4.CarLicen And UserForm1.TextBox2.Value = 1 And UserForm1.TextBox3.Value <= 399 Then
            ws.Cells(i, 7) = range1L
            ElseIf UserForm1.ComboBox1.Value = Car4.CarLicen And UserForm1.TextBox2.Value = 2 And UserForm1.TextBox3.Value <= 399 Then
                ws.Cells(i, 7) = range2L
                ElseIf UserForm1.ComboBox1.Value = Car4.CarLicen And UserForm1.TextBox2.Value = 3 And UserForm1.TextBox3.Value <= 399 Then
                    ws.Cells(i, 7) = range3L
                    ElseIf UserForm1.ComboBox1.Value = Car4.CarLicen And UserForm1.TextBox3.Value <= 600 Then
                        ws.Cells(i, 7) = rangeOver1
                        ElseIf UserForm1.ComboBox1.Value = Car4.CarLicen And UserForm1.TextBox3.Value <= 800 Then
                            ws.Cells(i, 7) = rangeOver2
                            ElseIf UserForm1.ComboBox1.Value = Car4.CarLicen And UserForm1.TextBox3.Value <= 1000 Then
                                ws.Cells(i, 7) = rangeOver3
                                ElseIf UserForm1.ComboBox1.Value = Car4.CarLicen And UserForm1.TextBox3.Value <= 1499 Then
                                    ws.Cells(i, 7) = rangeOver4
                                        ElseIf UserForm1.ComboBox1.Value = Car4.CarLicen And UserForm1.TextBox3.Value >= 1500 Then
                                            ws.Cells(i, 7) = rangeOver5
        End If
        If UserForm1.ComboBox1.Value = Car5.CarLicen And UserForm1.TextBox2.Value = 1 And UserForm1.TextBox3.Value <= 399 Then
            ws.Cells(i, 7) = range1L
            ElseIf UserForm1.ComboBox1.Value = Car5.CarLicen And UserForm1.TextBox2.Value = 2 And UserForm1.TextBox3.Value <= 399 Then
                ws.Cells(i, 7) = range2L
                ElseIf UserForm1.ComboBox1.Value = Car5.CarLicen And UserForm1.TextBox2.Value = 3 And UserForm1.TextBox3.Value <= 399 Then
                    ws.Cells(i, 7) = range3L
                    ElseIf UserForm1.ComboBox1.Value = Car5.CarLicen And UserForm1.TextBox3.Value <= 600 Then
                        ws.Cells(i, 7) = rangeOver1
                        ElseIf UserForm1.ComboBox1.Value = Car5.CarLicen And UserForm1.TextBox3.Value <= 800 Then
                            ws.Cells(i, 7) = rangeOver2
                            ElseIf UserForm1.ComboBox1.Value = Car5.CarLicen And UserForm1.TextBox3.Value <= 1000 Then
                                ws.Cells(i, 7) = rangeOver3
                                ElseIf UserForm1.ComboBox1.Value = Car5.CarLicen And UserForm1.TextBox3.Value <= 1499 Then
                                    ws.Cells(i, 7) = rangeOver4
                                        ElseIf UserForm1.ComboBox1.Value = Car5.CarLicen And UserForm1.TextBox3.Value >= 1500 Then
                                            ws.Cells(i, 7) = rangeOver5
        End If
        If UserForm1.ComboBox1.Value = Car6.CarLicen And UserForm1.TextBox2.Value = 1 And UserForm1.TextBox3.Value <= 399 Then
            ws.Cells(i, 7) = range1L
            ElseIf UserForm1.ComboBox1.Value = Car6.CarLicen And UserForm1.TextBox2.Value = 2 And UserForm1.TextBox3.Value <= 399 Then
                ws.Cells(i, 7) = range2L
                ElseIf UserForm1.ComboBox1.Value = Car6.CarLicen And UserForm1.TextBox2.Value = 3 And UserForm1.TextBox3.Value <= 399 Then
                    ws.Cells(i, 7) = range3L
                    ElseIf UserForm1.ComboBox1.Value = Car6.CarLicen And UserForm1.TextBox3.Value <= 600 Then
                        ws.Cells(i, 7) = rangeOver1
                        ElseIf UserForm1.ComboBox1.Value = Car6.CarLicen And UserForm1.TextBox3.Value <= 800 Then
                            ws.Cells(i, 7) = rangeOver2
                            ElseIf UserForm1.ComboBox1.Value = Car6.CarLicen And UserForm1.TextBox3.Value <= 1000 Then
                                ws.Cells(i, 7) = rangeOver3
                                ElseIf UserForm1.ComboBox1.Value = Car6.CarLicen And UserForm1.TextBox3.Value <= 1499 Then
                                    ws.Cells(i, 7) = rangeOver4
                                        ElseIf UserForm1.ComboBox1.Value = Car6.CarLicen And UserForm1.TextBox3.Value >= 1500 Then
                                            ws.Cells(i, 7) = rangeOver5
        End If
    'SizeM
        If UserForm1.ComboBox1.Value = Car7.CarLicen And UserForm1.TextBox2.Value = 1 And UserForm1.TextBox3.Value <= 399 Then
            ws.Cells(i, 7) = range1M
            ElseIf UserForm1.ComboBox1.Value = Car7.CarLicen And UserForm1.TextBox2.Value = 2 And UserForm1.TextBox3.Value <= 399 Then
                ws.Cells(i, 7) = range2M
                ElseIf UserForm1.ComboBox1.Value = Car7.CarLicen And UserForm1.TextBox2.Value = 3 And UserForm1.TextBox3.Value <= 399 Then
                    ws.Cells(i, 7) = range2M
                    ElseIf UserForm1.ComboBox1.Value = Car7.CarLicen And UserForm1.TextBox3.Value <= 600 Then
                        ws.Cells(i, 7) = rangeOver1
                        ElseIf UserForm1.ComboBox1.Value = Car7.CarLicen And UserForm1.TextBox3.Value <= 800 Then
                            ws.Cells(i, 7) = rangeOver2
                            ElseIf UserForm1.ComboBox1.Value = Car7.CarLicen And UserForm1.TextBox3.Value <= 1000 Then
                                ws.Cells(i, 7) = rangeOver3
                                ElseIf UserForm1.ComboBox1.Value = Car7.CarLicen And UserForm1.TextBox3.Value <= 1499 Then
                                    ws.Cells(i, 7) = rangeOver4
                                        ElseIf UserForm1.ComboBox1.Value = Car7.CarLicen And UserForm1.TextBox3.Value >= 1500 Then
                                            ws.Cells(i, 7) = rangeOver5
        End If
        If UserForm1.ComboBox1.Value = Car8.CarLicen And UserForm1.TextBox2.Value = 1 And UserForm1.TextBox3.Value <= 399 Then
            ws.Cells(i, 7) = range1M
            ElseIf UserForm1.ComboBox1.Value = Car8.CarLicen And UserForm1.TextBox2.Value = 2 And UserForm1.TextBox3.Value <= 399 Then
                ws.Cells(i, 7) = range2M
                ElseIf UserForm1.ComboBox1.Value = Car8.CarLicen And UserForm1.TextBox2.Value = 3 And UserForm1.TextBox3.Value <= 399 Then
                    ws.Cells(i, 7) = range2M
                    ElseIf UserForm1.ComboBox1.Value = Car8.CarLicen And UserForm1.TextBox3.Value <= 600 Then
                        ws.Cells(i, 7) = rangeOver1
                        ElseIf UserForm1.ComboBox1.Value = Car8.CarLicen And UserForm1.TextBox3.Value <= 800 Then
                            ws.Cells(i, 7) = rangeOver2
                            ElseIf UserForm1.ComboBox1.Value = Car8.CarLicen And UserForm1.TextBox3.Value <= 1000 Then
                                ws.Cells(i, 7) = rangeOver3
                                ElseIf UserForm1.ComboBox1.Value = Car8.CarLicen And UserForm1.TextBox3.Value <= 1499 Then
                                    ws.Cells(i, 7) = rangeOver4
                                        ElseIf UserForm1.ComboBox1.Value = Car8.CarLicen And UserForm1.TextBox3.Value >= 1500 Then
                                            ws.Cells(i, 7) = rangeOver5
        End If
        If UserForm1.ComboBox1.Value = Car9.CarLicen And UserForm1.TextBox2.Value = 1 And UserForm1.TextBox3.Value <= 399 Then
            ws.Cells(i, 7) = range1M
            ElseIf UserForm1.ComboBox1.Value = Car9.CarLicen And UserForm1.TextBox2.Value = 2 And UserForm1.TextBox3.Value <= 399 Then
                ws.Cells(i, 7) = range2M
                ElseIf UserForm1.ComboBox1.Value = Car9.CarLicen And UserForm1.TextBox2.Value = 3 And UserForm1.TextBox3.Value <= 399 Then
                    ws.Cells(i, 7) = range2M
                    ElseIf UserForm1.ComboBox1.Value = Car9.CarLicen And UserForm1.TextBox3.Value <= 600 Then
                        ws.Cells(i, 7) = rangeOver1
                        ElseIf UserForm1.ComboBox1.Value = Car9.CarLicen And UserForm1.TextBox3.Value <= 800 Then
                            ws.Cells(i, 7) = rangeOver2
                            ElseIf UserForm1.ComboBox1.Value = Car9.CarLicen And UserForm1.TextBox3.Value <= 1000 Then
                                ws.Cells(i, 7) = rangeOver3
                                ElseIf UserForm1.ComboBox1.Value = Car9.CarLicen And UserForm1.TextBox3.Value <= 1499 Then
                                    ws.Cells(i, 7) = rangeOver4
                                        ElseIf UserForm1.ComboBox1.Value = Car9.CarLicen And UserForm1.TextBox3.Value >= 1500 Then
                                            ws.Cells(i, 7) = rangeOver5
        End If
    'SizeS
        If UserForm1.ComboBox1.Value = Car10.CarLicen And UserForm1.TextBox2.Value = 1 And UserForm1.TextBox3.Value <= 399 Then
            ws.Cells(i, 7) = range1S
            ElseIf UserForm1.ComboBox1.Value = Car10.CarLicen And UserForm1.TextBox2.Value = 2 And UserForm1.TextBox3.Value <= 399 Then
                ws.Cells(i, 7) = range2S
                ElseIf UserForm1.ComboBox1.Value = Car10.CarLicen And UserForm1.TextBox2.Value = 3 And UserForm1.TextBox3.Value <= 399 Then
                    ws.Cells(i, 7) = range2S
                    ElseIf UserForm1.ComboBox1.Value = Car10.CarLicen And UserForm1.TextBox3.Value <= 600 Then
                        ws.Cells(i, 7) = rangeOver1
                        ElseIf UserForm1.ComboBox1.Value = Car10.CarLicen And UserForm1.TextBox3.Value <= 800 Then
                            ws.Cells(i, 7) = rangeOver2
                            ElseIf UserForm1.ComboBox1.Value = Car10.CarLicen And UserForm1.TextBox3.Value <= 1000 Then
                                ws.Cells(i, 7) = rangeOver3
                                ElseIf UserForm1.ComboBox1.Value = Car10.CarLicen And UserForm1.TextBox3.Value <= 1499 Then
                                    ws.Cells(i, 7) = rangeOver4
                                        ElseIf UserForm1.ComboBox1.Value = Car10.CarLicen And UserForm1.TextBox3.Value >= 1500 Then
                                            ws.Cells(i, 7) = rangeOver5
        End If
        If UserForm1.ComboBox1.Value = Car11.CarLicen And UserForm1.TextBox2.Value = 1 And UserForm1.TextBox3.Value <= 399 Then
            ws.Cells(i, 7) = range1S
            ElseIf UserForm1.ComboBox1.Value = Car11.CarLicen And UserForm1.TextBox2.Value = 2 And UserForm1.TextBox3.Value <= 399 Then
                ws.Cells(i, 7) = range2S
                ElseIf UserForm1.ComboBox1.Value = Car11.CarLicen And UserForm1.TextBox2.Value = 3 And UserForm1.TextBox3.Value <= 399 Then
                    ws.Cells(i, 7) = range2S
                    ElseIf UserForm1.ComboBox1.Value = Car11.CarLicen And UserForm1.TextBox3.Value <= 600 Then
                        ws.Cells(i, 7) = rangeOver1
                        ElseIf UserForm1.ComboBox1.Value = Car11.CarLicen And UserForm1.TextBox3.Value <= 800 Then
                            ws.Cells(i, 7) = rangeOver2
                            ElseIf UserForm1.ComboBox1.Value = Car11.CarLicen And UserForm1.TextBox3.Value <= 1000 Then
                                ws.Cells(i, 7) = rangeOver3
                                ElseIf UserForm1.ComboBox1.Value = Car11.CarLicen And UserForm1.TextBox3.Value <= 1499 Then
                                    ws.Cells(i, 7) = rangeOver4
                                        ElseIf UserForm1.ComboBox1.Value = Car11.CarLicen And UserForm1.TextBox3.Value >= 1500 Then
                                            ws.Cells(i, 7) = rangeOver5
        End If
You do not have the required permissions to view the files attached to this post.
User avatar
snasui
Site Admin
Site Admin
Posts: 31257
Joined: Sun Jan 24, 2010 12:33 pm
Location: Songkhla, Thailand
Excel Ver: 2010, 2019
Contact:

Re: วิธีจัดทำรายงานสรุปใบเสร็จรับเงิน แบบ LINK สูตร

#17

Post by snasui »

:D ตามโพสต์ #16 ยังติดขัดส่วนใดหรือไม่ อย่างไรหรือสามารถหาคำตอบได้แล้ว ช่วยแจ้งมาด้วยครับ

เมื่อมีการใช้ UserForm ในการรับค่า Input เราสามารถคำนวณค่าเที่ยวจากการกรอกข้อมูลของผู้ใช้ในขั้นตอนการ Input ก็ได้เช่นกัน จะได้ไม่ต้องมาคำนวณภายหลัง หรือติดเงื่อนไขใดจึงไม่สามารถคำนวณเมื่อมีการ Input ข้อมูลได้ครับ
sirthun
Member
Member
Posts: 9
Joined: Fri Jul 21, 2017 4:19 pm

Re: วิธีจัดทำรายงานสรุปใบเสร็จรับเงิน แบบ LINK สูตร

#18

Post by sirthun »

snasui wrote::D ตามโพสต์ #16 ยังติดขัดส่วนใดหรือไม่ อย่างไรหรือสามารถหาคำตอบได้แล้ว ช่วยแจ้งมาด้วยครับ

เมื่อมีการใช้ UserForm ในการรับค่า Input เราสามารถคำนวณค่าเที่ยวจากการกรอกข้อมูลของผู้ใช้ในขั้นตอนการ Input ก็ได้เช่นกัน จะได้ไม่ต้องมาคำนวณภายหลัง หรือติดเงื่อนไขใดจึงไม่สามารถคำนวณเมื่อมีการ Input ข้อมูลได้ครับ
ไม่ติดปัญหาแล้วครับอาจารย์ เรื่องการคำนวนค่าเที่ยว :D ขอบคุณอาจารย์มากครับ :cp:
Post Reply