I took the easy way and I create a new macro:
Sheets("Report").Select
Sheets("Report").Copy
and then I rename it. It's doing what I want. Thanks
I do have a different question, of course you remember the last code you help
me with. It's giving me a small problem. I want to bold and underline the
heading but sometimes it bold and underline some of the data do you know why?
thanks
As you can see I am an expert already "just jocking". But I learnt so much
thanks to you.
Here is my final code:
Sub GroupReport()
Dim CurWks As Worksheet
Dim RptWks As Worksheet
Dim iRow As Long
Dim oRow As Long
Dim FirstRow As Long
Dim LastRow As Long
Set CurWks = Worksheets("PreData")
Set RptWks = Worksheets("Report")
RptWks.Select
RptWks.Name = "Report"
Cells.Select
Selection.ClearContents
Range("A1").Select
With CurWks
FirstRow = 2
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
oRow = -1
For iRow = FirstRow To LastRow
If .Cells(iRow, "A").Value = .Cells(iRow - 1, "A").Value _
And .Cells(iRow, "B").Value = .Cells(iRow - 1, "B").Value Then
'same group, do nothing special
Else
'different group, do headers
oRow = oRow + 2
RptWks.Cells(oRow, "A").Value _
= "Owner: " & .Cells(iRow, "A").Value
oRow = oRow + 1
RptWks.Cells(oRow, "A").Value _
= "Beneficiary: " & .Cells(iRow, "B").Value
oRow = oRow + 2
RptWks.Cells(oRow, "B").Value = "COMPANY"
RptWks.Cells(oRow, "B").Font.Bold = True
RptWks.Cells(oRow, "B").Font.Underline = xlUnderlineStyleSingle
RptWks.Cells(oRow, "C").Value = "POLICY" & vbLf & "NUMBER"
RptWks.Cells(oRow, "c").Font.Bold = True
RptWks.Cells(oRow, "c").Font.Underline = xlUnderlineStyleSingle
RptWks.Cells(oRow, "D").Value = "ISSUE" & vbLf & "DATE"
RptWks.Cells(oRow, "D").Font.Bold = True
RptWks.Cells(oRow, "D").Font.Underline = xlUnderlineStyleSingle
RptWks.Cells(oRow, "E").Value = "FACE" & vbLf & "AMOUNT"
RptWks.Cells(oRow, "E").Font.Bold = True
RptWks.Cells(oRow, "E").Font.Underline = xlUnderlineStyleSingle
RptWks.Cells(oRow, "F").Value = "TYPE"
RptWks.Cells(oRow, "F").Font.Bold = True
RptWks.Cells(oRow, "F").Font.Underline = xlUnderlineStyleSingle
RptWks.Cells(oRow, "G").Value = "ANNUAL" & vbLf & "PREMIUM"
RptWks.Cells(oRow, "G").Font.Bold = True
RptWks.Cells(oRow, "G").Font.Underline = xlUnderlineStyleSingle
RptWks.Cells(oRow, "H").Value = "SURRENDER VALUE" & vbLf &
"AMOUNT"
RptWks.Cells(oRow, "H").Font.Bold = True
RptWks.Cells(oRow, "H").Font.Underline = xlUnderlineStyleSingle
RptWks.Cells(oRow, "I").Value = "SURRENDER VALUE" & vbLf &
"DATE"
RptWks.Cells(oRow, "I").Font.Bold = True
RptWks.Cells(oRow, "I").Font.Underline = xlUnderlineStyleSingle
'Format Columns
End If
'do the policy stuff
oRow = oRow + 1
RptWks.Cells(oRow, "B").Value = "'" & .Cells(iRow, "C").Value
RptWks.Cells(oRow, "C").Value = "'" & .Cells(iRow, "D").Value
RptWks.Cells(oRow, "D").Value = "'" & .Cells(iRow, "E").Value
RptWks.Cells(oRow, "E").Value = .Cells(iRow, "F").Value
RptWks.Cells(oRow, "F").Value = "'" & .Cells(iRow, "G").Value
RptWks.Cells(oRow, "G").Value = .Cells(iRow, "H").Value
RptWks.Cells(oRow, "H").Value = .Cells(iRow, "I").Value
RptWks.Cells(oRow, "I").Value = "'" & .Cells(iRow, "J").Value
RptWks.Cells(oRow, "E").NumberFormat = "#,000"
RptWks.Cells(oRow, "G").NumberFormat = "#,000"
RptWks.Cells(oRow, "H").NumberFormat = "#,000"
Next iRow
End With
End Sub
ielmrani said:
Sorry about the confusion, I did put C1 but the right cell is B1. when the
error comes out it highlight this line:
ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\" & myName & ".xls"
Is it the .saveas that gives you the runtime error?
[quoted text clipped - 25 lines]