เริ่มต้น เรียนรู้การเขียนโปรแกรม ด้วย vba Excel
พื้นฐานเริ่มต้น เขียนโปรแกรม โต้ตอบด้วยกล่องข้อความง่ายๆ ด้วย msgbox
การเขึยนโปรแกรม vba สั่งให้แสดงข้อความใน worksheet
การเขียนโปรแกรมสั่งให้ vba ทำงานทันทีเมื่อเปิดไฟล์ Excel
การเขียนโปรแกรม vba สร้างฟอร์มสำหรับ login ก่อนเข้าใช้งานระบบหรือก่อนเข้าไฟล์ต่างๆของ Excel
โค้ด vb สร้าง ปุ่ม Button เพื่อบันทึกไฟล์ excel เป็น PDF ตัวอย่างเป็นการบันทึก invoice เป็นเอกสาร pdf
การสร้างฟอร์ม (Form) ค้นหาข้อมูลพนักงาน ด้วย function Vlookup และ มีคำสั่งโค้ดแจกให้ทำ ดังนี้
Private Sub ComboBox1_Change()
Dim q, p As Long
q = Application.WorksheetFunction.CountA(Sheet1.Range("A:A"))
For p = 1 To 8
Me("textbox" & p).Value =
Application.WorksheetFunction.VLookup(ComboBox1.Value,
Sheet1.Range("A2:i13"), p + 1, 0)
Next p
End Sub
Private Sub CommandButton1_Click()
Unload Me
End Sub
เริ่มต้นง่ายๆกับการเขียนโปรแกรม การคำนวณพื้นที่ หลาย ๆ สูตร แบ่งด้วย Tab Page ด้วย VBA EXCEL
การสร้างโปรแกรมง่ายๆ โดยใช้ tab page เพื่อคำนวณหาพื้นที่สามเหลี่ยม ด้วย VBA EXCEL คลิปต่อจากการลองสร้างโปรแกรมเบื้องต้น
การสร้างโปรแกรมจับฉลาก ชิงโชค แจกรางวัล ในงานเทศกาลต่างๆ ใช้การสุ่มตัวเลข การค้นหา randbetween vlookup ด้วย Vba Excel มีโค้ดให้ ด้านล่างจร้าาาา ^_^
Joy To The World โดย Audionautix ได้รับอนุญาตภายใต้ ใบอนุญาต Creative Commons Attribution (https://creativecommons.org/licenses/by/4.0/)
ศิลปิน: http://audionautix.com/
======== VBA Excel Code ==============
Private Sub CommandButton1_Click()
Dim ran As Double
Dim n As String
Label3.ForeColor = vbWhite
For i = 1 To 9
Application.Wait Now + TimeValue("00:00:01")
ran = WorksheetFunction.RandBetween(1, 9)
n = WorksheetFunction.VLookup(ran, Sheet1.Range("A2:B10"), 2)
Label2.Caption = "¼Ùé⪤´Õ"
Label3.Caption = n
Next
Application.Wait Now + TimeValue("00:00:01")
Label3.Visible = False
Application.Wait Now + TimeValue("00:00:01")
Label3.ForeColor = vbGreen
Label3.Visible = True
End Sub
Private Sub CommandButton2_Click()
Label2.Caption = ""
Label3.Caption = ""
End Sub
การสร้างป้าย ฉลากราคาสำหรับติดสินค้า ง่ายๆ ด้วย VBA Excel มีโค้ดคำสั่งให้ด้านล่างเลยค่ะ
โค้ด vba สร้าง ฉลาก ป้ายราคา ติดที่สินค้า
Do
r = r + 1
Loop Until Cells(r, 1) = ""
Cells(r, 1).RowHeight = 25
Cells(r, 1).ColumnWidth = 20
Cells(r, 1).HorizontalAlignment = xlCenter
Cells(r, 1) = TextBox1.Value & " bath"
Cells(r + 1, 1) = "*" & TextBox2.Value & "*"
Cells(r + 1, 1).RowHeight = 85
Cells(r + 1, 1).ColumnWidth = 20
Cells(r + 1, 1).HorizontalAlignment = xlCenter
Cells(r + 1, 1).Select
With Selection.Font
.Name = "EAN-13"
.Size = 48
End With
Range(Cells(r, 1), Cells(r + 1, 1)).BorderAround Weight:=xlThick
Range(Cells(r, 1), Cells(r + 1, 1)).Select
Selection.Copy
Range(Cells(r, 2), Cells(r + 1, 2)).Select
ActiveSheet.Paste
Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Range(Cells(r, 3), Cells(r + 1, 3)).Select
ActiveSheet.Paste
Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Range(Cells(r, 4), Cells(r + 1, 4)).Select
ActiveSheet.Paste
Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Range(Cells(r, 5), Cells(r + 1, 5)).Select
ActiveSheet.Paste
Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, SkipBlanks:=False, Transpose:=False