: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

ต้องการให้ข้อมูลในกราฟเปลี่ยนตามข้อมูลที่กรอก

ฟอรัมถาม-ตอบปัญหาการใช้งานสูตรและฟังก์ชัน 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. กรุณาแจ้งผลการใช้งานเมื่อได้รับคำตอบว่าตรงกับความต้องการหรือไม่
Chayanit.c
Member
Member
Posts: 4
Joined: Tue Sep 01, 2020 8:44 am
Excel Ver: 2010,365

ต้องการให้ข้อมูลในกราฟเปลี่ยนตามข้อมูลที่กรอก

#1

Post by Chayanit.c »

ต้องการให้ข้อมูลในกราฟเปลี่ยนตามข้อมูลที่กรอก

Code: Select all

 
Dim PlanChart As String
Dim Titulo As String
Dim AreaSheett As String
Dim AreaSheettt As String
PlanChart = Sheet2.Name

Dim Linha As Double
Linha = 4
With Planilhal
     Do
     Linha = Linha + 1
     Loop Until .Cells(Linha, 2).Value = ""
End With
Linha = Linha - 1

Dim Sheett As Chart
Set Sheett = Sheets(PlanChart).ChartObjects("Chart 1").Chart


        If ComboBox1.Value = "2561" Then
            Titulo = Sheet1.Range("A2").Value
             AreaSheettt = " = " & Sheet1.Name & " ! " & Sheet1.Range("A3:A & Linha").Address
             AreaSheett = " = " & Sheet1.Name & " ! " & Sheet1.Range("B3:B & Linha ").Address
           

       With Sheett
     .HasTitle = True
     .ChartTitle.Text = Titulo
     .SeriesCollection(1).XValues = AreaSheettt
     .SeriesCollection(1).Values = AreaSheett
      End With

End If

 If ComboBox1.Value = "2562" Then
            Titulo = Sheet1.Range("D2").Value
             AreaSheettt = " = " & Sheet1.Name & " ! " & Sheet1.Range("D3:D & Linha ").Address
             AreaSheett = " = " & Sheet1.Name & " ! " & Sheet1.Range("E3:E & Linha ").Address
           

       With Sheett
     .HasTitle = True
     .ChartTitle.Text = Titulo
     .SeriesCollection(1).XValues = AreaSheettt
     .SeriesCollection(1).Values = AreaSheett
      End With

End If
If ComboBox1.Value = "2563" Then
            Titulo = Sheet1.Range("G2").Value
             AreaSheettt = " = " & Sheet1.Name & " ! " & Sheet1.Range("G3:G & Linha ").Address
             AreaSheett = " = " & Sheet1.Name & " ! " & Sheet1.Range("H3:H& Linha ").Address
           

       With Sheett
     .HasTitle = True
     .ChartTitle.Text = Titulo
     .SeriesCollection(1).XValues = AreaSheettt
     .SeriesCollection(1).Values = AreaSheett
      End With

End If

Call Carreger_Chart

Exit Sub
Erro:
MsgBox " Erro! ", vbCritical, " ERRO "
End Sub



Private Sub UserForm_Initialize()
Call Carreger_Chart

ComboBox1.AddItem " 2561 "
ComboBox1.AddItem " 2562 "
ComboBox1.AddItem " 2563 "

End Sub

มันติดเหลือง Loop Until .Cells(Linha, 2).Value = "" บรรทัดนี้ และขึ้น Run time error 424 : Object Required
You do not have the required permissions to view the files attached to this post.
User avatar
snasui
Site Admin
Site Admin
Posts: 31253
Joined: Sun Jan 24, 2010 12:33 pm
Location: Songkhla, Thailand
Excel Ver: 2010, 2019
Contact:

Re: ต้องการให้ข้อมูลในกราฟเปลี่ยนตามข้อมูลที่กรอก

#2

Post by snasui »

:D With Statement ใน Procedure Private Sub ComboBox1_Change() เขียนไม่ถูกต้องครับ

การอ้างอิงจะต้องบอกโปรแกรมทราบว่าเป็นชีตไหน เช่น

Code: Select all

With Worksheets(PlanChart)
     Do
     Linha = Linha + 1
     Loop Until .Cells(Linha, 2).Value = ""
End With
ใน Procedure Private Sub UserForm_Initialize() Assign ค่าให้กับ Item ของ ComboBox ไม่ตรงกับที่จะใช้จริง การเขียนเป็น ComboBox1.AddItem " 2561 " คือให้มีวรรคครอบ เมื่อตอนตรวจสอบการเปลี่ยนแปลงค่าก็ต้องมีวรรคครอบด้วย เช่น If ComboBox1.Value = " 2561 " Then อย่างนี้ถึงจะตรวจสอบกันได้ครับ
Chayanit.c
Member
Member
Posts: 4
Joined: Tue Sep 01, 2020 8:44 am
Excel Ver: 2010,365

Re: ต้องการให้ข้อมูลในกราฟเปลี่ยนตามข้อมูลที่กรอก

#3

Post by Chayanit.c »

snasui wrote: Tue Sep 01, 2020 10:27 am :D With Statement ใน Procedure Private Sub ComboBox1_Change() เขียนไม่ถูกต้องครับ

การอ้างอิงจะต้องบอกโปรแกรมทราบว่าเป็นชีตไหน เช่น

Code: Select all

With Worksheets(PlanChart)
     Do
     Linha = Linha + 1
     Loop Until .Cells(Linha, 2).Value = ""
End With
ใน Procedure Private Sub UserForm_Initialize() Assign ค่าให้กับ Item ของ ComboBox ไม่ตรงกับที่จะใช้จริง การเขียนเป็น ComboBox1.AddItem " 2561 " คือให้มีวรรคครอบ เมื่อตอนตรวจสอบการเปลี่ยนแปลงค่าก็ต้องมีวรรคครอบด้วย เช่น If ComboBox1.Value = " 2561 " Then อย่างนี้ถึงจะตรวจสอบกันได้ครับ

ลองเปลี่ยนตามที่แนะนำแล้วค่ะ พอ run ออกมามันขึ้น Error ที่ AreaSheettt = " = " & Sheet1.Name & " ! " & Sheet1.Range("D3:D & Linha ").Address มันขึ้นว่า run time error 1004 : Method ' Rangs ' of object_'worksheet' failed

Code: Select all

If ComboBox1.Value = " 2562 " Then
            Titulo = Sheet1.Range("D2").Value
             AreaSheettt = " = " & Sheet1.Name & " ! " & Sheet1.Range("D3:D & Linha ").Address
             AreaSheett = " = " & Sheet1.Name & " ! " & Sheet1.Range("E3:E & Linha ").Address

       With Sheett
     .HasTitle = True
     .ChartTitle.Text = Titulo
     .SeriesCollection(1).XValues = AreaSheettt
     .SeriesCollection(1).Values = AreaSheett
      End With
You do not have the required permissions to view the files attached to this post.
User avatar
snasui
Site Admin
Site Admin
Posts: 31253
Joined: Sun Jan 24, 2010 12:33 pm
Location: Songkhla, Thailand
Excel Ver: 2010, 2019
Contact:

Re: ต้องการให้ข้อมูลในกราฟเปลี่ยนตามข้อมูลที่กรอก

#4

Post by snasui »

:D เขียน Statement ที่ใช้เชื่อมตัวแปรไม่ถูกต้องครับ

จาก .Range("D3:D & Linha ").Address ปรับเป็น .Range("D3:D" & Linha).Address

ซึ่งจะต้องแก้ในทุก ๆ ตำแหน่งที่เขียนไว้ลักษณะนี้ครับ
Chayanit.c
Member
Member
Posts: 4
Joined: Tue Sep 01, 2020 8:44 am
Excel Ver: 2010,365

Re: ต้องการให้ข้อมูลในกราฟเปลี่ยนตามข้อมูลที่กรอก

#5

Post by Chayanit.c »

snasui wrote: Tue Sep 01, 2020 6:54 pm :D เขียน Statement ที่ใช้เชื่อมตัวแปรไม่ถูกต้องครับ

จาก .Range("D3:D & Linha ").Address ปรับเป็น .Range("D3:D" & Linha).Address

ซึ่งจะต้องแก้ในทุก ๆ ตำแหน่งที่เขียนไว้ลักษณะนี้ครับ


เปลี่ยนทุกตำแหน่งตามที่แนะนำแล้วค่ะ แต่มันยังติด error อยู่เลยค่ะ ซึ่งหนูพยายามแก้เองแล้วแต่จนปัญญา

Code: Select all

 Private Sub ComboBox1_Change() 
มันติดเหลืองตัวนี้ค่ะ แล้วขึ้นว่า compile error : sub or Function not defined

Code: Select all

Private Sub ComboBox1_Change()
'On Error GoTo Erro

Dim PlanChart As String
Dim Titulo As String
Dim AreaSheett As String
Dim AreaSheettt As String
PlanChart = Sheet2.Name


Dim Linha As Double
Linha = 4
With Worksheet(PlanChart)
     Do
     Linha = Linha + 1
     Loop Until .Cells(Linha, 2).Value = ""
End With


Dim Sheett As Chart
Set Sheett = Sheets(PlanChart).ChartObjects(" Chart 1 ").Chart


        If ComboBox1.Value = " 2561 " Then
            Titulo = Sheet1.Range("A2").Value
             AreaSheettt = " = " & Sheet1.Name & " ! " & Sheet1.Range(" A3:A " & Linha).Address
             AreaSheett = " = " & Sheet1.Name & " ! " & Sheet1.Range(" B3:B " & Linha).Address
           

       With Sheett
     .HasTitle = True
     .ChartTitle.Text = Titulo
     .SeriesCollection(1).XValues = AreaSheettt
     .SeriesCollection(1).Values = AreaSheett
      End With

End If

 If ComboBox1.Value = " 2562 " Then
            Titulo = " 2562 "
             AreaSheettt = " = " & Sheet1.Name & " ! " & Sheet1.Range(" D3:D " & Linha).Address
             AreaSheett = " = " & Sheet1.Name & " ! " & Sheet1.Range(" E3:E " & Linha).Address
           

       With Sheett
     .HasTitle = True
     .ChartTitle.Text = Titulo
     .SeriesCollection(1).XValues = AreaSheettt
     .SeriesCollection(1).Values = AreaSheett
      End With

End If
If ComboBox1.Value = " 2563 " Then
            Titulo = Sheet1.Range("G2").Value
             AreaSheettt = " = " & Sheet1.Name & " ! " & Sheet1.Range(" G3:G " & Linha).Address
             AreaSheett = " = " & Sheet1.Name & " ! " & Sheet1.Range(" H3:H " & Linha).Address
           

       With Sheett
     .HasTitle = True
     .ChartTitle.Text = Titulo
     .SeriesCollection(1).XValues = AreaSheettt
     .SeriesCollection(1).Values = AreaSheett
      End With

End If

Call Carreger_Chart

Exit Sub
Erro:
MsgBox " Erro! ", vbCritical, " ERRO "
End Sub
[/coed]
You do not have the required permissions to view the files attached to this post.
Chayanit.c
Member
Member
Posts: 4
Joined: Tue Sep 01, 2020 8:44 am
Excel Ver: 2010,365

Re: ต้องการให้ข้อมูลในกราฟเปลี่ยนตามข้อมูลที่กรอก

#6

Post by Chayanit.c »

snasui wrote: Tue Sep 01, 2020 6:54 pm :D เขียน Statement ที่ใช้เชื่อมตัวแปรไม่ถูกต้องครับ

จาก .Range("D3:D & Linha ").Address ปรับเป็น .Range("D3:D" & Linha).Address

ซึ่งจะต้องแก้ในทุก ๆ ตำแหน่งที่เขียนไว้ลักษณะนี้ครับ


เปลี่ยนทุกตำแหน่งตามที่แนะนำแล้วค่ะ แต่มันยังติด error อยู่เลยค่ะ ซึ่งหนูพยายามแก้เองแล้วแต่จนปัญญา

Code: Select all

 Private Sub ComboBox1_Change() 
มันติดเหลืองตัวนี้ค่ะ แล้วขึ้นว่า compile error : sub or Function not defined

Code: Select all

Private Sub ComboBox1_Change()
'On Error GoTo Erro

Dim PlanChart As String
Dim Titulo As String
Dim AreaSheett As String
Dim AreaSheettt As String
PlanChart = Sheet2.Name


Dim Linha As Double
Linha = 4
With Worksheet(PlanChart)
     Do
     Linha = Linha + 1
     Loop Until .Cells(Linha, 2).Value = ""
End With


Dim Sheett As Chart
Set Sheett = Sheets(PlanChart).ChartObjects(" Chart 1 ").Chart


        If ComboBox1.Value = " 2561 " Then
            Titulo = Sheet1.Range("A2").Value
             AreaSheettt = " = " & Sheet1.Name & " ! " & Sheet1.Range(" A3:A " & Linha).Address
             AreaSheett = " = " & Sheet1.Name & " ! " & Sheet1.Range(" B3:B " & Linha).Address
           

       With Sheett
     .HasTitle = True
     .ChartTitle.Text = Titulo
     .SeriesCollection(1).XValues = AreaSheettt
     .SeriesCollection(1).Values = AreaSheett
      End With

End If

 If ComboBox1.Value = " 2562 " Then
            Titulo = " 2562 "
             AreaSheettt = " = " & Sheet1.Name & " ! " & Sheet1.Range(" D3:D " & Linha).Address
             AreaSheett = " = " & Sheet1.Name & " ! " & Sheet1.Range(" E3:E " & Linha).Address
           

       With Sheett
     .HasTitle = True
     .ChartTitle.Text = Titulo
     .SeriesCollection(1).XValues = AreaSheettt
     .SeriesCollection(1).Values = AreaSheett
      End With

End If
If ComboBox1.Value = " 2563 " Then
            Titulo = Sheet1.Range("G2").Value
             AreaSheettt = " = " & Sheet1.Name & " ! " & Sheet1.Range(" G3:G " & Linha).Address
             AreaSheett = " = " & Sheet1.Name & " ! " & Sheet1.Range(" H3:H " & Linha).Address
           

       With Sheett
     .HasTitle = True
     .ChartTitle.Text = Titulo
     .SeriesCollection(1).XValues = AreaSheettt
     .SeriesCollection(1).Values = AreaSheett
      End With

End If

Call Carreger_Chart

Exit Sub
Erro:
MsgBox " Erro! ", vbCritical, " ERRO "
End Sub
[/coed]
You do not have the required permissions to view the files attached to this post.
User avatar
snasui
Site Admin
Site Admin
Posts: 31253
Joined: Sun Jan 24, 2010 12:33 pm
Location: Songkhla, Thailand
Excel Ver: 2010, 2019
Contact:

Re: ต้องการให้ข้อมูลในกราฟเปลี่ยนตามข้อมูลที่กรอก

#7

Post by snasui »

:D แก้คำว่า Worksheet ให้เป็น Worksheets ครับ

นอกจากนั้น แก้พวกค่าที่ครอบด้วยเครื่องหมายฟันหนู ค่าใดก็ตามที่ไปเพิ่มเครื่องหมายวรรคเข้าไปทีหลัง ให้ลบวรรคออกทั้งหมด

โพสต์ #4 ผมหมายถึงการครอบตัวแปรด้วยฟันหนูที่เขียนมานั้นไม่ถูกต้อง Statement ใดที่ครอบตัวแปรด้วยฟันหนูให้แก้ตามที่ผมบอก ต้องเข้าใจว่าสิ่งไหนเรียกว่าตัวแปร สิ่งไหนไม่ใช่ตัวแปร ซึ่งถ้าเขียน Code ข้างต้นมาเองควรจะต้องทราบสิ่งเหล่านี้ครับ
Post Reply