2017-10-09 97 views
-1

首先我的免责声明。虽然我有一些编程背景,但我不熟练使用VB脚本,所以我可能需要一些手持这一点,但我非常感谢任何帮助你美妙的人可以呈现。在Excel中创建基于条件标准的打印按钮

林创建打印按钮,将打印标准为基础的工作表中,用户将在打字。嗯,基本上我需要的脚本来检查某些细胞在一排,如果有这些单元格中的数据,移动到下一个线。冲洗并重复,直到在某些单元格中出现没有数据的行,然后根据数据自动打印正确数量的页面。我希望这是有道理的。我希望这是有道理的。

+0

请分享您的工作。我们可以建议/帮助。 – Valli

+0

我没有。我在研究过程中发现了很少的代码片段,但是没有经过VB脚本的正式培训,就像对代码进行解密一样。这就是为什么我在这里寻求帮助。我不要求你为我做这件事,我要求你指出我正确的方向。不知道为什么你认为我的帐户应该是负面的,但无论如何。 – Gehn47

+0

所以你正在寻找第一个空白单元格? MATCH(TRUE,INDEX(C:C =“”,0),0)。这将返回列C中第一个空白单元格的行号。 – Valli

回答

0

我试着写一段代码来检查某些列,并在所有列都为空时返回值。希望对你有帮助

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子句添加一个条件

+1

没有,这将工作完美。然后,我可以根据找到的第一行或列是完全空白的页面添加.printout。谢谢。 – Gehn47