ดึงข้อมูลแล้วขึ้น #VALUE!
Posted: Fri Jan 21, 2022 1:17 pm
เรียนอาจารย์ทุกท่าน
เนื่องจากผมเลือกข้อมูล จาก Sheet BILLPRINT&REVISED แต่ Cell ที่ไม่มีข้อมูลขึ้น #VALUE! ต้องแก้ไขอย่างไรครับ
จากตัวอย่างภาพโดยเลือกข้อมูลที่ต้องการ Cell AX8 ครับ
ตรง Module - SubPG
เนื่องจากผมเลือกข้อมูล จาก Sheet BILLPRINT&REVISED แต่ Cell ที่ไม่มีข้อมูลขึ้น #VALUE! ต้องแก้ไขอย่างไรครับ
จากตัวอย่างภาพโดยเลือกข้อมูลที่ต้องการ Cell AX8 ครับ
ตรง Module - SubPG
Code: Select all
Sub CallOrdered(OrderRow As Long)
Application.CutCopyMode = False
Application.ScreenUpdating = False
Dim TB As ListObject, OrderTB As ListObject
Dim SelRow As Long: SelRow = 0
Set OrderTB = TBs.selectTable("Order", "OrderTB")
Set TB = TBs.selectTable("Customers", "CustomerTB")
With ThisWorkbook.Sheets("BILLPRINT&REVISED")
.Cells(8, "AX") = OrderTB.Range.Cells(OrderRow, "D")
.Cells(20, "H") = OrderTB.Range.Cells(OrderRow, "E")
On Error Resume Next
SelRow = TB.DataBodyRange.Columns("D").Find(.Cells(20, "H"), lookat:=xlWhole).Row
If SelRow = 0 Then
MsgBox "No customer found in database"
Exit Sub
End If
'Customer detail
.Cells(25, "H") = TB.Range.Cells(SelRow, "E")
.Cells(29, "O") = TB.Range.Cells(SelRow, "F")
.Cells(31, "O") = TB.Range.Cells(SelRow, "G")
.Cells(33, "O") = TB.Range.Cells(SelRow, "H")
.Cells(33, "AF") = TB.Range.Cells(SelRow, "I")
.Cells(25, "AP") = TB.Range.Cells(SelRow, "J")
.Cells(28, "AP") = TB.Range.Cells(SelRow, "K")
.Cells(31, "AU") = TB.Range.Cells(SelRow, "C")
'Product detail
.Cells(40, "O") = OrderTB.Range.Cells(OrderRow, "F")
.Cells(40, "AL") = OrderTB.Range.Cells(OrderRow, "O") 'QLT.
.Cells(40, "AP") = OrderTB.Range.Cells(OrderRow, "P") 'Price
.Cells(42, "O") = OrderTB.Range.Cells(OrderRow, "G")
.Cells(44, "O") = OrderTB.Range.Cells(OrderRow, "H")
.Cells(46, "O") = OrderTB.Range.Cells(OrderRow, "J")
.Cells(48, "O") = OrderTB.Range.Cells(OrderRow, "K")
.Cells(48, "AL") = OrderTB.Range.Cells(OrderRow, "L") 'QLT.
.Cells(48, "AP") = OrderTB.Range.Cells(OrderRow, "M") 'Price
.Cells(46, "A") = OrderTB.Range.Cells(OrderRow, "I")
.Cells(56, "O") = OrderTB.Range.Cells(OrderRow, "R")
.Cells(56, "AL") = OrderTB.Range.Cells(OrderRow, "AA") 'QLT.
.Cells(56, "AP") = OrderTB.Range.Cells(OrderRow, "AB") 'Price
.Cells(58, "O") = OrderTB.Range.Cells(OrderRow, "S")
.Cells(60, "O") = OrderTB.Range.Cells(OrderRow, "T")
.Cells(62, "O") = OrderTB.Range.Cells(OrderRow, "V")
.Cells(64, "O") = OrderTB.Range.Cells(OrderRow, "W")
.Cells(64, "AL") = OrderTB.Range.Cells(OrderRow, "X") 'QLT.
.Cells(64, "AP") = OrderTB.Range.Cells(OrderRow, "Y") 'Price
.Cells(62, "A") = OrderTB.Range.Cells(OrderRow, "U")
'Delivery
.Cells(70, "O") = OrderTB.Range.Cells(OrderRow, "AF")
.Cells(70, "AL") = OrderTB.Range.Cells(OrderRow, "AG")
.Cells(70, "AP") = OrderTB.Range.Cells(OrderRow, "AH")
'Remark Detail
.Cells(72, "H") = OrderTB.Range.Cells(OrderRow, "AD")
.Cells(74, "H") = OrderTB.Range.Cells(OrderRow, "AE")
'Detail
.Cells(78, "AH") = OrderTB.Range.Cells(OrderRow, "AN")
'Sale
.Cells(97, "AP") = OrderTB.Range.Cells(OrderRow, "AO")
End With
Application.CutCopyMode = True
Application.ScreenUpdating = True
End Sub