snasui.com ยินดีต้อนรับ
ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
ฟอรัมถาม-ตอบปัญหาการใช้งานสูตรและฟังก์ชัน Excel
Forum rules
ไม่อนุญาตให้ใช้ภาษาแชทในการถามและตอบปัญหา ไม่ใช้คำว่า "คับ" หรือ "อ่ะครับ" แทนคำว่า "ครับ" ไม่ใช้คำว่า "เด๋ว" แทนคำว่า "เดี๋ยว" เป็นต้น เนื่องจากเมื่อแปลเป็นภาษาต่างประเทศแล้วจะให้ความหมายผิดไปจากที่ควรจะเป็น
ห้ามถามโดยระบุชื่อผู้ตอบและต้องตั้งชื่อกระทู้ให้สื่อถึงปัญหาที่จะถาม ไม่ตั้งชื่อว่า ช่วยด้วยครับ, มีปัญหามาปรึกษาครับ เป็นต้น
กรุณาอธิบายปัญหาและระบุคำตอบที่ต้องการมาในกระทู้ด้วยเสมอถึงแม้จะอธิบายไว้ในไฟล์แนบแล้วก็ตาม ทั้งนี้เพื่ออำนวยความสะดวกแก่เพื่อนสมาชิกในการค้นหาข้อมูล
กรุณาแนบไฟล์ตัวอย่างพร้อมแสดงคำตอบที่ถูกต้องมาในไฟล์ด้วยเพื่อให้ง่ายต่อการทำความเข้าใจและสะดวกต่อการตอบคำถาม (ขนาดไฟล์ไม่เกิน 500Kb ขนาดภาพไม่เกิน 800*600 Pixel) ไม่แนบเป็น Link มาจากแหล่งอื่นที่อาจจะถูกลบทิ้งไปโดยต้นทางในภายหลัง นอกจากนี้ไม่ควรแนบไฟล์ที่มีข้อมูลสำคัญอันก่อให้เกิดความเสียหายกับตนเองและผู้อื่น
กรณีเป็นคำถามเกี่ยวกับ Programming เช่น VBA, VB.Net, C#, SQL ฯลฯ ต้องลองเขียนมาเองก่อนเสมอ ถามเฉพาะที่ติดปัญหา ระบุ Module, Procedure ที่ติดปัญหาให้ชัดเจน กรุณาโพสต์ Code ให้แสดงเป็น Code คือเปิดด้วย [code] และปิดด้วย [/code] ตัวอย่างเช่น [code]dim r as range[/code] เพื่อให้แตกต่างจากข้อความทั่วไป สะดวกในการอ่านและทดสอบ (คลิกเพื่อดูตัวอย่าง)
กรุณาแจ้งผลการใช้งานเมื่อได้รับคำตอบว่าตรงกับความต้องการหรือไม่
snasui
Site Admin
Posts: 31253 Joined: Sun Jan 24, 2010 12:33 pm
Location: Songkhla, Thailand
Excel Ver: 2010, 2019
Contact:
#21
Post
by snasui » Mon Aug 06, 2012 9:32 pm
หลักการคือให้สร้างตัวแปรที่นับเฉพาะเซลล์ที่ไม่เป็นค่าว่าง สามารถใช้สูตรนับเซลล์ที่ไม่ว่าง
เช่น
=Countif(A:A,"<>")
เพื่อจะนับว่าค่าที่ไม่ว่างมีเท่าไร ให้เอามาใส่ใน ListBox เพียงเท่านั้น
yodpao.b
Gold
Posts: 1608 Joined: Tue Jul 19, 2011 2:47 pm
Excel Ver: 2013,excel standard
#22
Post
by yodpao.b » Mon Aug 06, 2012 9:47 pm
snasui wrote: =Countif(A:A,"<>")
ไม่เข้าใจครับอาจาร์ย
ผมได้แนบไฟล์มาให้ครับ
ขอร้องอาจาร์ยช่วยแก้ให้หน่อยนะครับ
ส่วนคำถามแรกแก้ปัญหาได้แล้วครับ
You do not have the required permissions to view the files attached to this post.
snasui
Site Admin
Posts: 31253 Joined: Sun Jan 24, 2010 12:33 pm
Location: Songkhla, Thailand
Excel Ver: 2010, 2019
Contact:
#23
Post
by snasui » Mon Aug 06, 2012 10:40 pm
ช่วยแนบไฟล์ตัวอย่างมาใหม่ครับ ชีทที่เกี่ยวข้องไม่ควรลบออกไป เพราะจะทำให้สูตรแสดงค่าผิดพลาด
yodpao.b
Gold
Posts: 1608 Joined: Tue Jul 19, 2011 2:47 pm
Excel Ver: 2013,excel standard
#24
Post
by yodpao.b » Tue Aug 07, 2012 2:31 am
ฟอร์มตัวนี้เอาไว้โชว์เป็นรายงานเฉยครับ
แสดงค่าอย่างเดียว
แต่ไม่ให้แสดงวงกลมที่ไม่ใช้
You do not have the required permissions to view the files attached to this post.
snasui
Site Admin
Posts: 31253 Joined: Sun Jan 24, 2010 12:33 pm
Location: Songkhla, Thailand
Excel Ver: 2010, 2019
Contact:
#25
Post
by snasui » Tue Aug 07, 2012 8:42 am
ลองปรับ Code เป็นตามด้านล่างครับ
Code: Select all
Private Sub UserForm_Initialize()
'On Error Resume Next
'Call MacroScreenUpdat_F
'Call UnProtectAllSheets
Sheets("ReportReturn").Select
TB21.Text = Sheets("ReportReturn").Range("C7")
With Me.ListBox1
.BoundColumn = 1
.ColumnCount = 8
.ColumnHeads = True
.TextColumn = True
If Range("C9") = "" Then
.RowSource = "ReportReturn!C9:N9"
Else
.RowSource = "ReportReturn!C9:N" & Application.Match( _
9.99999999999999E+307, Sheets("ReportReturn") _
.Range("N1:N" & Rows.Count)) 'xlLastRow("ReportReturn")
End If
.ListStyle = fmListStyleOption
.ListIndex = 0
End With
End Sub
yodpao.b
Gold
Posts: 1608 Joined: Tue Jul 19, 2011 2:47 pm
Excel Ver: 2013,excel standard
#26
Post
by yodpao.b » Tue Aug 07, 2012 8:11 pm
ขอบคุณมากครับอาจาร์ยวงกลมไม่โชว์แล้วครับ
วันนี้ขอถามอีก 2 ข้อนะครับได้แล้ว ผมจะได้เริ่มเขียน ฟอร์มที่ใช้ Listbox
ข้อที่ 1 ในการมาร์คในวงกลม แล้วให้เอาชื่อมาโชว์ใน Textbox ดังรูป
Untitled21.gif
ข้อที่ 2 นำบรรทัดข้อมูลที่มาร์ค คัดลอกไปที่ Sheet2
ขอบคุณครับ
You do not have the required permissions to view the files attached to this post.
snasui
Site Admin
Posts: 31253 Joined: Sun Jan 24, 2010 12:33 pm
Location: Songkhla, Thailand
Excel Ver: 2010, 2019
Contact:
#27
Post
by snasui » Tue Aug 07, 2012 8:29 pm
ลองปรับ Code เป็นตามด้านล่างครับ
Code: Select all
Private Sub ListBox1_Change()
Dim SourceRange As Excel.Range
Dim Val1 As String, Val2 As String, Val3 As String
If (ListBox1.RowSource <> vbNullString) Then
'Get Range that the ListBox is bound to
Set SourceRange = Range(ListBox1.RowSource)
Else
'Get first data row
Set SourceRange = Range("Sheet1!A2:C2")
Exit Sub
End If
Val1 = ListBox1.Value
'Get the value of the second column
Val2 = SourceRange.Offset(ListBox1.ListIndex, 1).Resize(1, 1).Value
'Get the value of the third column
Val3 = SourceRange.Offset(ListBox1.ListIndex, 2).Resize(1, 1).Value
'Concatenate the three values together and display them in Label1
'Label1.Caption = "Selected Data: " & vbNewLine & Val1 & " " & Val2 & " " & Val3
With UserForm1
.TextBox1 = Val1
.TextBox2 = Val2
.TextBox3 = Val3
.TextBox11 = Val1
End With
'Clean Up
Set SourceRange = Nothing
End Sub
yodpao.b
Gold
Posts: 1608 Joined: Tue Jul 19, 2011 2:47 pm
Excel Ver: 2013,excel standard
#28
Post
by yodpao.b » Tue Aug 07, 2012 10:30 pm
ขอบคุณมากครับอาจาร์ย เดี๋ยวขอทดลองใช้ก่อน
อาจาร์ยอย่าลืมข้อ 2 นะครับ(ไม่ได้เขียน Code อะไรเลย)เพราะไม่เข้าใจ
snasui
Site Admin
Posts: 31253 Joined: Sun Jan 24, 2010 12:33 pm
Location: Songkhla, Thailand
Excel Ver: 2010, 2019
Contact:
#29
Post
by snasui » Tue Aug 07, 2012 10:37 pm
ข้อสองลองสังเกตว่าผมนำค่าเข้าไปไว้ใน TextBox แต่ละอันได้อย่างไร แล้วลองประยุกต์วิธีนั้นไปใช้กับ Sheet2 ติดตรงไหนก็แนบ Code ที่ปรับเองแล้วมาถามกันครับ
yodpao.b
Gold
Posts: 1608 Joined: Tue Jul 19, 2011 2:47 pm
Excel Ver: 2013,excel standard
#30
Post
by yodpao.b » Wed Aug 08, 2012 2:06 am
ครับผมวันพร่งนี้ผมจะรองนำไปประยุกต์ดูครับ
You do not have the required permissions to view the files attached to this post.