Page 1 of 1

รบกวนปรึกษาเรื่องการ Set Print Area หลายชีทที่มีข้อต่างกัน

Posted: Tue Jul 30, 2013 10:29 pm
by 0549
เรียน อาจารย์ที่เคารพ

ผมมีปัญหาเรื่องการ ใช้ VBA ในการ Set Print Area หลายชีท ที่มีข้อมูลต่างกัน
ประเด็นปัญหาคือ
1.Code vba ที่เขียน Set Print Area มัน Set เหมือนกันทุกหน้าไม่ (เหมือน Sheet "GL") - ใช้ Code vba ที่ 2

สิ่งที่ต้องการ คือ
1.อยากให้ Set Print Area โดยดูที่ข้อมูลแต่ละ Sheet

รบกวนขอความรู้เพิ่มเติมด้วยครับ ปล.โพสครั้งแรกครับ
Test.xlsm

Re: รบกวนปรึกษาเรื่องการ Set Print Area หลายชีทที่มีข้อต่างก

Posted: Wed Jul 31, 2013 1:04 am
by tupthai
นำ LastRow ไปไว้ใน For Each
แล้วเปลี่ยนจาก
Cells(Rows.Count, "A").End(xlUp).Row
เป็น
ws.Cells(Rows.Count, "A").End(xlUp).Row

Code: Select all

Sub PrintAreas_UsedR()
    Dim ws As Worksheet
    Dim LastRow As Long
    'LastRow = Cells(Rows.Count, "A").End(xlUp).Row
    For Each ws In ActiveWorkbook.Worksheets
        LastRow = ws.Cells(Rows.Count, "A").End(xlUp).Row
        If Not ws.Name = "Template" And Not ws.Name = "summary" Then
            ws.PageSetup.PrintArea = "A1:S" & LastRow
        End If
    Next ws
End Sub

Re: รบกวนปรึกษาเรื่องการ Set Print Area หลายชีทที่มีข้อต่างก

Posted: Wed Jul 31, 2013 1:42 am
by 0549
ขอบคุณครับ คุณ Tupthai