首先是我的免责声明。虽然我有一些编程背景,但我并不精通VB脚本,所以我可能需要一些手握这个,但我非常感谢你们精彩的人们可以提供的任何帮助。
我创建一个打印按钮,根据用户输入的条件打印工作表。基本上我需要脚本来连续检查某些单元格,如果这些单元格中有数据,请移到下一行。冲洗并重复,直到您在某些单元格中没有数据的行,然后根据数据自动打印正确数量的页面。我希望这是有道理的。我希望这是有道理的。
答案 0 :(得分:1)
我尝试编写一段代码来检查某些列,并在所有这些列都为空时返回值。希望能帮到你
Sub Printing()
Dim CheckCol1 As Integer, CheckCol2 As Integer
Dim rowCount As Integer, rowCount1 As Integer, rowCount2 As Integer, currentRow As Integer
Dim currentRowValue1 As String, currentRowValue2 As String
Dim found As String
found = "No"
CheckCol1 = 1 'column A has a value of 1
CheckCol2 = 2 'column B has a value of 2
rowCount1 = Cells(Rows.Count, CheckCol1).End(xlUp).Row
rowCount2 = Cells(Rows.Count, CheckCol2).End(xlUp).Row
rowCount = Application.Max(rowCount1, rowCount2)
' find the first blank cell on both the columns
For currentRow = 1 To rowCount
currentRowValue1 = Cells(currentRow, CheckCol1).Value
currentRowValue2 = Cells(currentRow, CheckCol2).Value
If (IsEmpty(currentRowValue1) Or currentRowValue1 = "") And (IsEmpty(currentRowValue2) Or currentRowValue2 = "") Then
MsgBox ("No data on Column A and B in row" & currentRow)
found = "Yes"
End If
Next
If found = "No" Then ' This will return rowcount+1 when the columns have values throughout the range
MsgBox ("No data on Column A and B in row" & rowCount + 1)
End If
End Sub
注意: - 您可以通过添加少量变量来增加要检查的列数。您可以通过添加Checkcol3,rowcount3,currentrowvalue3并向if子句添加一个条件来尝试添加第三列