Page 1 of 1
รูปแบบ code การใส่เส้นขอบทุกด้าน
Posted: Mon Feb 25, 2019 4:39 pm
by sosadboy
ผมอยากทราบว่ามีโค๊ดที่ใส้เส้นขอบให้เซลล์แบบสั้นๆ ไหมครับ เนื่องจากผมบันทึกมาโครแล้วโค๊ดยาวมากครับ ฝากผู้รู้ช่วยตอบทีครับ
ไม่งั้นผมคงต้องไปนั่งตัดโค๊ดแล้วรันดูอย่างเดียว
Re: รูปแบบ code การใส่เส้นขอบทุกด้าน
Posted: Mon Feb 25, 2019 5:25 pm
by puriwutpokin
แนบไฟล์ตัวอย่าง และโค้ดที่บันทึกมา ด้วยครับ จะได้ให้เพื่อนๆสมาชิก ได้ช่วยดูและแก้ไขให้ได้ครับ
Re: รูปแบบ code การใส่เส้นขอบทุกด้าน
Posted: Tue Feb 26, 2019 3:52 pm
by sosadboy
ขอโทษครับที่ช้าไปหน่อย ตามไฟล์ที่แนบ ที่เซลล์ "D5" ผมใส่เส้นขอบให้กับเซลล์ โค๊ดที่บันทึกมาโครได้คือ
Code: Select all
Sub Macro1()
Range("D5").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).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 = xlThin
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
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With อยากทราบว่าสามารถย่อโค๊ดข้างต้นนี้ได้หรือไม่ครับ
Re: รูปแบบ code การใส่เส้นขอบทุกด้าน
Posted: Tue Feb 26, 2019 5:55 pm
by puriwutpokin
sosadboy wrote: Tue Feb 26, 2019 3:52 pm
ขอโทษครับที่ช้าไปหน่อย ตามไฟล์ที่แนบ ที่เซลล์ "D5" ผมใส่เส้นขอบให้กับเซลล์ โค๊ดที่บันทึกมาโครได้คือ
Code: Select all
Sub Macro1()
Range("D5").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).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 = xlThin
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
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With อยากทราบว่าสามารถย่อโค๊ดข้างต้นนี้ได้หรือไม่ครับ
ปรับเป็น
Code: Select all
Sub Macro1()
Range("D5").Select
With Selection
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeRight).LineStyle = xlContinuous
End With
End Sub
Re: รูปแบบ code การใส่เส้นขอบทุกด้าน
Posted: Wed Feb 27, 2019 3:10 pm
by sosadboy
ขอบคุณมากมากครับ สำหรับโค๊ดในลักษณะเดียวกัน ก็สามารถทำได้เช่นกันใช่ไหมครับ เช่นบรรทัดที่ค่า=0 สามารถตัดออกได้เลยใช่ไหมครับ
Re: รูปแบบ code การใส่เส้นขอบทุกด้าน
Posted: Wed Feb 27, 2019 3:16 pm
by puriwutpokin
sosadboy wrote: Wed Feb 27, 2019 3:10 pm
ขอบคุณมากมากครับ สำหรับโค๊ดในลักษณะเดียวกัน ก็สามารถทำได้เช่นกันใช่ไหมครับ เช่นบรรทัดที่ค่า=0 สามารถตัดออกได้เลยใช่ไหมครับ
ใช่ครับ
Re: รูปแบบ code การใส่เส้นขอบทุกด้าน
Posted: Thu Feb 28, 2019 6:58 am
by snasui
ตัวอย่างการปรับให้เหลือบรรทัดเดียวครับ
Code: Select all
Sub Macro1()
Range("D5").Borders.LineStyle = xlContinuous
End Sub
Re: รูปแบบ code การใส่เส้นขอบทุกด้าน
Posted: Thu Feb 28, 2019 12:36 pm
by sosadboy
ขอบคุณอาจารย์มากครับ เป็นประโยชน์กับผมอย่างมากเลยครับ