有人可以帮我解决下面的VBA代码。我希望显示在同一列的不同行中,而不是在同一单元格的不同行中显示结果。
非常感谢您的帮助!!!
private void print(String txt, String printerName) {
PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);
PrintService service = findPrintService(printerName, printService);
try {
DocPrintJob job = service.createPrintJob();
byte[] bytes;
bytes = txt.getBytes("UTF-8");
Doc doc = new SimpleDoc(bytes, flavor, null);
job.print(doc, null);
//byte[] cutP = new byte[] { 0x1d, 'V', 1 };
} catch (Exception e){
e.printStackTrace();
}
}
答案 0 :(得分:0)
此子项将旧值传递给触发sub的范围以下的单元格。并传递低于相同范围的新值2个单元格。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Oldvalue As String '<~ declare old value
Dim Newvalue As String '<~ declare new value
Application.EnableEvents = True '<~enable events( idunno why)
On Error GoTo ExitSub '<~ simple error handler
If Not Target.Column = 8 Then GoTo ExitSub '<~ if the change not happened in col8 then exit
If Target.SpecialCells(xlCellTypeAllValidation) Is Nothing Then GoTo ExitSub
If Target.Value = "" Then GoTo ExitSub '<~ if the new value is blank then exit
Application.EnableEvents = False '<~ disableevents
Newvalue = Target.Value '<~ pass new value into a variable
Application.Undo '<~ force undo
Oldvalue = Target.Value '<~ pass previous value into a variable
Target.Value = Newvalue '<~ give new value
If Not Oldvalue = "" Then '<~ check if old value is blank
If InStr(1, Oldvalue, Newvalue) = 0 Then '<~ check if the old value
Target.Offset(1, 0).Value = "Old Value: " & Oldvalue '<~ pass old value to a cell below the
Target.Offset(2, 0).Value = "New Value: " & Newvalue '<~ range that made a change
End If
End If
ExitSub:
Application.EnableEvents = True
End Sub