Hello,
I am having problems with my VBA code. First, I can't get the selected cells to convert to number format (font in red). Second, I get run-time error 5 Invalid procedure call or argument when trying to create a pivot table (font in green). Any and all help is greatly appreciated!
I am having problems with my VBA code. First, I can't get the selected cells to convert to number format (font in red). Second, I get run-time error 5 Invalid procedure call or argument when trying to create a pivot table (font in green). Any and all help is greatly appreciated!
Code:
Sub MM27_Profile()
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim ws3 As Worksheet
Dim ws4 As Worksheet
Dim ws5 As Worksheet
Dim ws6 As Worksheet
Dim x As Integer
Dim ws2rows As Integer
Dim myrows As Integer
Dim i As Integer
Dim sFileName As String
Application.ScreenUpdating = False
Set ws1 = Worksheets("Output Filter Applied")
Set ws2 = Worksheets("Disease Assessment 01")
Set ws3 = Worksheets("Disease Assessment")
Set ws4 = Worksheets("Hematology 01")
Set ws5 = Worksheets("Chemistry 01")
Application.DisplayAlerts = False
ws1.Delete
Application.DisplayAlerts = True
Set ws6 = ActiveWorkbook.Worksheets.Add(After:=ws5)
ws6.Name = "Patient Profile"
ws2.Select
Range("A1:F1").Select
Range("A1:F1").Cut Destination:=ws6.Range("A1:F1")
Range("A2:D2").Select
Range("A2:D2").Cut Destination:=ws6.Range("G1:J1")
Rows("1:4").Select
Selection.Delete Shift:=xlUp
[COLOR=#ff0000]myrows = WorksheetFunction.CountA(ws2.Range("A:A"))
For i = 2 To myrows
ws2.Cells(i, 4).NumberFormat = "0"
Next i[/COLOR]
[COLOR=#008000]ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Disease Assessment 01", Version:=xlPivotTableVersion14).CreatePivotTable _
TableDestination:="'Patient Profile'!R3C1", TableName:="Immunoglobulins", DefaultVersion _
:=xlPivotTableVersion14
[/COLOR]
ws6.Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("Immunoglobulins").PivotFields("LAB")
.Orientation = xlColumnField
.Position = 1
End With
With ActiveSheet.PivotTables("Immunoglobulins").PivotFields("Visit Date")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("Immunoglobulins").AddDataField ActiveSheet.PivotTables( _
"Immunoglobulins").PivotFields("Value"), "Sum of Value", xlSum
ActiveSheet.PivotTables("Immunoglobulins").ColumnGrand = False
ActiveSheet.PivotTables("Immunoglobulins").RowGrand = False
Rows("3:3").Select
Selection.EntireRow.Hidden = True
End Sub