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] เพื่อให้แตกต่างจากข้อความทั่วไป สะดวกในการอ่านและทดสอบ (คลิกเพื่อดูตัวอย่าง)
กรุณาแจ้งผลการใช้งานเมื่อได้รับคำตอบว่าตรงกับความต้องการหรือไม่
dal252244
Member
Posts: 17 Joined: Fri Sep 21, 2012 8:57 am
#1
Post
by dal252244 » Wed Nov 04, 2015 2:09 pm
รบกวนผู้รู้หน่อยนะครับ ผมไม่มีความรู้เรื่อง VB จึงอยากรบกวนช่วยแนะนำการเขียนหน่อยครับ โดยคอลัมน์ A มีข้อมูลเลข 1 กับ 2 อยากจะเขียน VB ให้เลือกเฉพาะข้อมูลที่มีเลข 2 แล้วทำการขีดเส้นทึบแถวนั้นทั้งแถวครับ เนื่องจากไม่มีความรู้ทางด้านนี้ รบกวนช่วยแนะนำด้วยนะครับว่าจะเขียนเป็น VB หรือใช้วิธีใดได้บ้าง
snasui
Site Admin
Posts: 31255 Joined: Sun Jan 24, 2010 12:33 pm
Location: Songkhla, Thailand
Excel Ver: 2010, 2019
Contact:
#2
Post
by snasui » Wed Nov 04, 2015 7:00 pm
การถามตอบ VBA ต้องเป็นไปตามกฎการใช้บอร์ดข้อ 5 ด้านบนครับ
dal252244
Member
Posts: 17 Joined: Fri Sep 21, 2012 8:57 am
#3
Post
by dal252244 » Thu Nov 05, 2015 4:16 pm
ขอโทษด้วยครับ ผมลองทำจากการบันทึกMacro แล้วลองแก้เบื้องต้น ทำได้ในระดับหนึ่งครับ แต่เวลาจะเพ่ิม เลข 2 ในแถวถัดลงมา เมื่อกดรันสูตรเส้นขีดล่างไม่ขึ้นครับ ยังคงขึ้นที่เดิม ไม่ทราบว่าผมต้องแก้ตรงไหนครับ รบกวนด้วยนะครับ
Code: Select all
Sub Macro3()
'
' Macro3 Macro
'
'
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
ActiveSheet.Range("$T:$T").AutoFilter Field:=1, Criteria1:="2"
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 1
Range("A6:S2000").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlHairline
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlHairline
End With
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
ActiveSheet.Range("$T:$T").AutoFilter Field:=1
End Sub
dal252244
Member
Posts: 17 Joined: Fri Sep 21, 2012 8:57 am
#4
Post
by dal252244 » Thu Nov 05, 2015 4:19 pm
ไฟล์แนบครับ
You do not have the required permissions to view the files attached to this post.
snasui
Site Admin
Posts: 31255 Joined: Sun Jan 24, 2010 12:33 pm
Location: Songkhla, Thailand
Excel Ver: 2010, 2019
Contact:
#5
Post
by snasui » Thu Nov 05, 2015 6:28 pm
ตัวอย่าง Code ครับ
Code: Select all
Sub line6()
'
' line6 Macro
'
'
For Each Rng In ActiveSheet.Range("$T$6:$T$60001").SpecialCells(xlCellTypeConstants)
If Rng.Value = 2 Then
Range(Range("A" & Rng.Row), Cells(Rng.Row, "S")).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlHairline
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Else
Range(Range("A" & Rng.Row), Cells(Rng.Row, "S")).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
' With Selection.Borders(xlEdgeTop)
' .LineStyle = xlContinuous
' .ColorIndex = 0
' .TintAndShade = 0
' .Weight = xlHairline
' End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlHairline
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
End If
Next Rng
Range("B6").Select
End Sub
dal252244
Member
Posts: 17 Joined: Fri Sep 21, 2012 8:57 am
#6
Post
by dal252244 » Fri Nov 06, 2015 8:53 am
ทำได้แล้วครับ ขอบคุณมากครับอาจารย์