Tôi có một bảng tính như sau:Định dạng có điều kiện Excel không hiển thị khi in?
Với dạng có điều kiện để làm nổi bật hàng đầu mười con số của tôi trong cột U.
Tôi có mã VBA sau trong bảng tính của tôi :
Và đoạn mã này để vô hiệu hóa tính và tái phép tính:
Option Explicit
Sub code2()
MsgBox "This will take upto 2 minutes."
Application.ScreenUpdating = False
Dim WB As Workbook
Dim I As Long
Dim j As Long
Dim Lastrow As Long
Dim WeekNum As Integer
'Clear Data Sheet
On Error GoTo Message
With ThisWorkbook.Worksheets("Data")
.Rows(2 & ":" & .Rows.Count).ClearContents
End With
On Error Resume Next
Set WB = Workbooks("L.O. Lines Delivery Tracker.xlsm")
On Error GoTo 0
If WB Is Nothing Then 'open workbook if not open
Set WB = Workbooks.Open("G:\WH DISPO\(3) PROMOTIONS\(18) L.O. Delivery Tracking\L.O. Lines Delivery Tracker.xlsm")
End If
' ======= Edit #2 , also for DEBUG ======
With WB.Worksheets(1)
Lastrow = .Cells(.Rows.Count, "G").End(xlUp).Row
j = 2
For I = 7 To Lastrow
WeekNum = CInt(Format(.Range("G" & I).Value, "ww", 2) - 1)
' === For DEBUG ONLY ===
Debug.Print CInt(ThisWorkbook.Worksheets(2).Range("B9").Value)
Debug.Print WeekNum
Debug.Print CInt(ThisWorkbook.Worksheets(2).Range("D9").Value)
Debug.Print Year(.Range("G" & I).Value)
Debug.Print ThisWorkbook.Worksheets(2).Range("B6").Value
Debug.Print .Range("M" & I).Value
If CInt(ThisWorkbook.Worksheets(2).Range("B9").Value) = WeekNum Then ' check if Month equals the value in "A1"
If CInt(ThisWorkbook.Worksheets(2).Range("D9").Value) = Year(.Range("G" & I).Value) Then ' check if Year equals the value in "A2"
If ThisWorkbook.Worksheets(2).Range("B6").Value = .Range("M" & I).Value Then
ThisWorkbook.Worksheets(3).Range("A" & j).Value = .Range("G" & I).Value
ThisWorkbook.Worksheets(3).Range("B" & j).Formula = "=WeekNum(A" & j & ",21)"
ThisWorkbook.Worksheets(3).Range("C" & j).Value = .Range("L" & I).Value
ThisWorkbook.Worksheets(3).Range("D" & j).Value = .Range("D" & I).Value
ThisWorkbook.Worksheets(3).Range("E" & j).Value = .Range("E" & I).Value
ThisWorkbook.Worksheets(3).Range("F" & j).Value = .Range("F" & I).Value
ThisWorkbook.Worksheets(3).Range("g" & j).Value = .Range("p" & I).Value
ThisWorkbook.Worksheets(3).Range("H" & j).Value = .Range("H" & I).Value
ThisWorkbook.Worksheets(3).Range("I" & j).Value = .Range("I" & I).Value
ThisWorkbook.Worksheets(3).Range("J" & j).Value = .Range("J" & I).Value
ThisWorkbook.Worksheets(3).Range("k" & j).Value = .Range("Q" & I).Value
ThisWorkbook.Worksheets(3).Range("L" & j).Value = .Range("m" & I).Value
j = j + 1
End If
End If
End If
Next I
End With
Application.Calculation = xlAutomatic
ThisWorkbook.Worksheets("Data").UsedRange.Columns("B:B").Calculate
ThisWorkbook.Worksheets(2).UsedRange.Columns("B:AA").Calculate
On Error GoTo Message
With ThisWorkbook.Worksheets(2) '<--| change "mysheet" to your actual sheet name
Intersect(.Range(Rows(14), .UsedRange.Rows(.UsedRange.Rows.Count)), .Range("G:G")).WrapText = True
Intersect(.Range(Rows(14), .UsedRange.Rows(.UsedRange.Rows.Count)), .Range("G:G")).EntireRow.AutoFit
End With
End
ThisWorkbook.Worksheets(2).Activate
Application.ScreenUpdating = True
Exit Sub
Message:
On Error Resume Next
Exit Sub
End Sub
Tôi không biết nếu đó là vì tôi đang quay calclulations và tắt, nhưng khi tôi muốn in tờ này, ngay cả khi tôi in dưới dạng pdf. Định dạng có điều kiện không hiển thị.
Xin vui lòng ai đó có thể cho tôi biết tôi đang làm gì sai?
Edit: Tôi cũng đã thử thêm này để workbook:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
For Each wk In Worksheets
wk.Calculate
Next
End Sub
Nó vẫn không hoạt động.
Chỉ cần làm một chút googling và tìm thấy [this] (https://answers.microsoft.com/en-us/msoffice/forum/msoffice_excel-mso_other/conditional-formatting-does-not-update/08fed959-df7a -4e43-a0ae-a2aa5f587edd) Trong cửa sổ thuộc tính trong trình soạn thảo mã VBA, có phải 'EnableFormatConditionsCalculation' được đặt thành true không? – jsheeran
@jsheeran ok cảm ơn vì vậy tôi đã thử đặt: ThisWorkbook.Worksheets (2).EnableFormatConditionsCalculation trong sự kiện in trước và điều này đã không tạo sự khác biệt – user7415328
Đó là một thuộc tính, không phải là một phương pháp. Thay đổi nó thành 'ThisWorkbook.Worksheets (2) .EnableFormatConditionsCalculation = True' có tạo sự khác biệt không? – jsheeran