I have two Sheets. On the first one you fill the information needed and another one is basically template where information from Sheet(1) goes.
Sheet(2) is full of formulas like =IF(Sheet(1)!A1=””;””;Sheet(1)!A1).
So on the Sheet(2) is a lot of values with “” that are basically blank. I want to delete entire row if in this row there are no text.
So if the row looks like:
A33(“”) B33(“”) C33(“”) D33(“”) E33(“”) F33(“”) G33(some text) H33(“”) I33(“”) – it should stay
A34(“”) B34(“”) C34(“”) D34(“”) E34(“”) F34(“”) G34(“”) H34(“”) I34(“”) – should be deleted
Also on the Sheet(2) I have merged cells and text from corresponding cell in Sheet(1) does not fit in there. I want to wrap these cells they are in range Sheet(2)!B31:D68 (B31:D31 and B32:D32 and so on) are merged.
Here is my code but for example Wrap for merged cells does not work. Code is hiding the rows I need them to be deleted. Code is also hiding rows with my text in Sheet(2) coming as result from 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
tag is misplaced here. Apart of that,Autofit
does not work with merged cells, that is a known problem, unfortunately. - A.S.HAutofit
that doesnt work, notWrap
. Anyway is the the only problem you are facing? If not, try first to work with unmerged stuff and do the merging/wrapping at the very end. - A.S.H