Page 1 of 1
เปลี่ยนโค้ดจาก xlup เป็น xlright แต่กลับขึ้น error VBA Runtime Error 1004 “Application-defined or Object-defined error"
Posted: Wed Mar 18, 2020 5:44 pm
by nuttanan2140
สวัสดีครับ พอดีว่าผมต้องการจะหาค่าเฉลี่ยของค่าทุกค่าใน exel จากช่องปัจจุบันไปช่องด้านซ้ายสุดที่มีค่าอยู่ แต่มันกลับขึ้น error ว่า "VBA Runtime Error 1004 “Application-defined or Object-defined error" ผมสามารถแก้ทางยังไงได้บ้างครับ ขอบคุณนะครับ
Code: Select all
Dim xbar(30000) As Double
xbar(i) = Application.WorksheetFunction.Average(Range(Cells(3, i + 6), Cells(3, i + 6).End(xlRight)))
ผมแนบไฟล์งานที่เกี่ยว อยู่ใน class module8 นะครับ
Re: เปลี่ยนโค้ดจาก xlup เป็น xlright แต่กลับขึ้น error VBA Runtime Error 1004 “Application-defined or Object-defined er
Posted: Wed Mar 18, 2020 8:03 pm
by puriwutpokin
ไม่แน่ใจเข้าใจถูกไหมครับ
ปรับดูครับ
Code: Select all
xxbar(i) = Application.WorksheetFunction.Average(Range(Cells(3, 1 + 6), Cells(3, 1 + 6)).End(xlToRight))
Re: เปลี่ยนโค้ดจาก xlup เป็น xlright แต่กลับขึ้น error VBA Runtime Error 1004 “Application-defined or Object-defined er
Posted: Wed Mar 18, 2020 9:05 pm
by puriwutpokin
puriwutpokin wrote: Wed Mar 18, 2020 8:03 pm
ไม่แน่ใจเข้าใจถูกไหมครับ
ปรับดูครับ
Code: Select all
xxbar(i) = Application.WorksheetFunction.Average(Range(Cells(3, 1 + 6), Cells(3, 1 + 6)).End(xlToRight))
แก้ไขครับ
Code: Select all
xbar(i) = Application.WorksheetFunction.Average(Range(Cells(3, i + 6), Cells(3, i + 6).End(xlToRight)))
Re: เปลี่ยนโค้ดจาก xlup เป็น xlright แต่กลับขึ้น error VBA Runtime Error 1004 “Application-defined or Object-defined er
Posted: Thu Mar 19, 2020 3:15 pm
by nuttanan2140
มันขึ้นว่า "unable to get the average property of the worksheet function class " หมายความว่ายังไงหรอครับ??
Re: เปลี่ยนโค้ดจาก xlup เป็น xlright แต่กลับขึ้น error VBA Runtime Error 1004 “Application-defined or Object-defined er
Posted: Thu Mar 19, 2020 4:50 pm
by puriwutpokin
ลองเปลี่ยนเป็นดูครับ
Code: Select all
xbar(i) = Application.Average(Range(Cells(3, i + 6), Cells(3, i + 6).End(xlToRight)))