简体   繁体   English

Excel VBA 只打印一行

[英]Excel VBA Print Just One Line

I'm using this code for add new items to next blank line.我正在使用此代码将新项目添加到下一个空行。

    Private Sub Ekle_Butonu_Click()

    Dim LastRow As Long, ws As Worksheet

    Set ws = Sayfa1

    LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row + 1
    ws.Range("A" & LastRow).Value = Tarih_B
    ws.Range("C" & LastRow).Value = Kaynak_B
    ws.Range("E" & LastRow).Value = Aciklama_B
    ws.Range("I" & LastRow).Value = Tutar_B

End Sub

And I want to print just this added line.我想打印只是这添加的行。 Can you help me ?.你能帮助我吗 ?。

You need to look into the PageSetup.PrintArea property.您需要查看PageSetup.PrintArea属性。 For example:例如:

Sub Test()

Dim lr As Long

With Sayfa1
    lr = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
    .Cells(lr, 1).Value = Tarih_B
    .Cells(lr, 3).Value = Kaynak_B
    .Cells(lr, 5).Value = Aciklama_B
    .Cells(lr, 9).Value = Tutar_B
    .PageSetup.PrintArea = Replace("A?,C?,E?,I?", "?", lr)
    .PrintOut
End With

End Sub

As per your comment, If I understand you correctly, there are more cells in that same line you want to include:根据您的评论,如果我理解正确,您希望在同一行中包含更多单元格:

.PageSetup.PrintArea = Replace("A?:J?", "?", lr)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM