我有兩個表格。第一個填寫需要的信息,另一個基本上是Sheet(1)中信息的模板。 (2)充滿了類似= IF(Sheet(1)!A1 =「」;「」; Sheet(1)!A1)的公式。
所以在表(2)上有很多值「」,基本上都是空白的。如果在這一行中沒有文本,我想刪除整行。包裝合併的單元格,刪除單元格的行Excel Excel VBA
因此,如果該行的樣子:
A33(「」),B33(「」),C33(「」)D33(「」)E33(「」),F33(「」),G33(一些文本) H33(「」)I33(「」) - 它應該停留
A34(「」)B34(「」)C34(「」)D34(「」)E34 「」)H34(「」)I34(「」) - 應該被刪除
同樣在表(2)上,我已經合併單元格和來自Sheet(1)中相應單元格的文本不適合那裏。我想將這些單元格放在範圍表(2)!B31:D68(B31:D31和B32:D32等)中進行合併。
這是我的代碼,但例如Wrap for merged cells does not work。代碼隱藏了我需要刪除的行。代碼也是將Sheet(2)中的文本隱藏在來自Sheet(1)的結果中。
Sub AutofitRows()
Dim CL As Range
For Each CL In ActiveWorkbook.Sheets(2).Range("A30:I68")
If CL.WrapText Then CL.rows.AutoFit
Next
End Sub
Sub removecellswithemptycells()
ActiveWorkbook.Sheets(2).Select
Set rr = Range("A30:J66")
For Each cell In rr
cell.Select
If cell.HasFormula = True And cell.Value = "" And cell.EntireRow.Hidden = False Then rows(cell.Row).EntireRow.Hidden = True
Next cell
End Sub
Sub removecellswithemptycells_pos2()
ActiveWorkbook.Sheets(2).Select
Set rr = Range("A21:J22")
For Each cell In rr
cell.Select
If cell.HasFormula = True And cell.Value = "" And cell.EntireRow.Hidden = False Then rows(cell.Row).EntireRow.Hidden = True
Next cell
End Sub
Sub dothefiles()
Dim NewPath As String
Dim iFileName$, iRow&
NewPath = Application.ThisWorkbook.Path & "\" & "Order"
If Dir(NewPath, 63) = "" Then MkDir NewPath
ActiveWorkbook.Sheets(2).Select
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=NewPath & "\" & [Sheet(1)!C17] & "-" & [Sheet(1)!C6] & " " & "Order" & " " & [Sheet(1)!C10] & " " & Date & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=No, _
OpenAfterPublish:=False
iFileName = NewPath & "\" & [Sheet(1)!C17] & "-" & [Sheet(1)!C6] & " " & "Order" & " " & [Sheet(1)!C10] & " " & Date & ".xls"
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.Calculation = xlManual
ThisWorkbook.Sheets(2).Copy
With ActiveWorkbook.ActiveSheet
.Buttons.Delete '.Shapes("Button 1").Delete
.UsedRange.Value = .UsedRange.Value
For iRow = .Cells(.rows.Count, 2).End(xlUp).Row To 5 Step -1
If Application.CountA(.rows(iRow)) = 1 Then .rows(iRow).Delete
Next
.SaveAs iFileName, xlExcel8: .Parent.Close
End With
Application.Calculation = xlAutomatic
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Sub doitallplease()
Call AutofitRows
Call removecellswithemptycells
Call removecellswithemptycells_pos2
Call dothefiles
End Sub
我認爲'wrap'標籤在這裏放錯了地方。除此之外,'Autofit'不適用於合併的單元格,這是一個已知的問題,不幸的是。 –
如果無法爲合併單元格換行,我可以'unmerge'它們,但是我需要''修改'然後通過我的Range並檢查單元格高度是否需要增加。 – mrwd
這是'自動調整',不工作,不'包裹'。無論如何是你面臨的唯一問題?如果不是,首先嚐試使用未合併的東西,並在最後進行合併/包裝。 –