Dim wb As ThisWorkbook, ws_port As Worksheet, pth As String, wf As WorksheetFunction, wb_zfin As Workbook, cl As Range, cl1 As Range
Dim ws_1 As Worksheet, ws_2 As Worksheet, ws_3 As Worksheet, ws_4 As Worksheet, ws_5 As Worksheet, ws_6 As Worksheet, ws_7 As Worksheet, ws_8 As Worksheet, ws_9 As Worksheet, ws_10 As Worksheet
Dim ws_11 As Worksheet, ws_12 As Worksheet, ws As Worksheet, s As Variant, arr As Variant
Dim pc1 As String, pc2 As String, pc3 As String, pc4 As String, pc5 As String
Set wb = ThisWorkbook
Set wf = WorksheetFunction
Set ws_port = wb.Worksheets("Portfolio")
pth = "\\rsmca8-fil01\vol2\ATN_ORG\ATN Program Porfolio\input reports\ZFIN.xlsx"
On Error Resume Next
Set wb_zfin = Workbooks("ZFIN.xlsx")
On Error GoTo 0
If wb_zfin Is Nothing Then
Set wb_zfin = Workbooks.Open(Filename:=pth, ReadOnly:=True)
End If
Set ws_1 = wb_zfin.Worksheets("1")
Set ws_2 = wb_zfin.Worksheets("2")
Set ws_3 = wb_zfin.Worksheets("3")
Set ws_4 = wb_zfin.Worksheets("4")
Set ws_5 = wb_zfin.Worksheets("5")
Set ws_6 = wb_zfin.Worksheets("6")
Set ws_7 = wb_zfin.Worksheets("7")
Set ws_8 = wb_zfin.Worksheets("8")
Set ws_9 = wb_zfin.Worksheets("9")
Set ws_10 = wb_zfin.Worksheets("10")
Set ws_11 = wb_zfin.Worksheets("11")
Set ws_12 = wb_zfin.Worksheets("12")
For Each ws In wb_zfin.Worksheets
ws.Range("B1").EntireColumn.Insert
ws.Range("B1").EntireColumn.NumberFormat = "General"
lastrow = ws.Cells(Rows.Count, 3).End(xlUp).Row
For Each cl In ws.Range("C7:C" & lastrow)
Select Case Left(cl, 6)
Case " ": cl.Offset(0, -1).Value = Mid(cl.Value, 7, 10)
Case "** ": Select Case Mid(cl, 7, 2)
Case "IS": cl.Offset(0, -1).Value = "T3-" & Mid(cl, 9, 5)
Case "MS": cl.Offset(0, -1).Value = "R1-" & Mid(cl, 9, 5)
End Select
Case "*** ": s = Split(cl, " ")
cl.Offset(0, -1).Value = wf.Trim(wf.Clean(s(3)))
Case Else:
End Select
Next cl
Next ws
wb.Activate
Application.ScreenUpdating = False
For Each cl In ws_port.Range("curr_month").Offset(3, 0).Resize(Cells(Rows.Count, 2).End(xlUp).Row - 3, 1)
Select Case Len(wf.Trim(wf.Clean(LCase(cl))))
Case 10: Select Case Left(wf.Trim(wf.Clean(LCase(cl))), 2)
Case "bp", "p1": Select Case Right(wf.Trim(wf.Clean(LCase(cl))), 3)
Case "all": For Each cl1 In ws_port.Range(Cells(cl.Row, Range("curr_zfin").Offset(, -5).Column), Cells(cl.Row, Range("curr_zfin").Column))
cl1.Formula = "=IF(ISNA(Vlookup($C" & cl.Row & ",'[ZFIN.xlsx]" & Cells(Range("curr_zfin").Row, cl1.Column) & "'!$B:$L,3,False)),0,Vlookup($C" & cl.Row & ",'[ZFIN.xlsx]" & Cells(Range("curr_zfin").Row, cl1.Column) & "'!$B:$L,3,False))"
cl1.Value = cl1.Value * -1
cl1.NumberFormat = "_(* #,##0_);_(* (#,##0);_(* "" - ""??_);_(@_)"
Next cl1
Case Else: For Each cl1 In ws_port.Range(Cells(cl.Row, Range("curr_zfin").Offset(0, -5).Column), Cells(cl.Row, Range("curr_zfin").Column))
cl1.Formula = "=IF(ISNA(Vlookup($B" & cl.Row & ",'[ZFIN.xlsx]" & Cells(Range("curr_zfin").Row, cl1.Column) & "'!$B:$L,3,False)),0,Vlookup($B" & cl.Row & ",'[ZFIN.xlsx]" & Cells(Range("curr_zfin").Row, cl1.Column) & "'!$B:$L,3,False))"
cl1.Value = cl1.Value * -1
cl1.NumberFormat = "_(* #,##0_);_(* (#,##0);_(* "" - ""??_);_(@_)"
Next cl1
End Select
Case Else: For Each cl1 In ws_port.Range(Cells(cl.Row, Range("curr_zfin").Offset(, -5).Column), Cells(cl.Row, Range("curr_zfin").Column))
cl1.Formula = "=IF(ISNA(Vlookup($B" & cl.Row & ",'[ZFIN.xlsx]" & Cells(Range("curr_zfin").Row, cl1.Column) & "'!$B:$L,3,False)),0,Vlookup($B" & cl.Row & ",'[ZFIN.xlsx]" & Cells(Range("curr_zfin").Row, cl1.Column) & "'!$B:$L,3,False))"
cl1.Value = cl1.Value * -1
cl1.NumberFormat = "_(* #,##0_);_(* (#,##0);_(* "" - ""??_);_(@_)"
Next cl1
End Select
Case 14: Select Case Left(wf.Trim(wf.Clean(LCase(cl))), 2)
Case "bp", "p1": pc1 = Left(wf.Trim(wf.Clean(LCase(cl))), 10)
pc2 = Left(wf.Trim(wf.Clean(LCase(cl))), 7) & Mid(cl, 12, 3)
arr = Array(pc1, pc2)
For Each cl1 In ws_port.Range(Cells(cl.Row, Range("curr_zfin").Offset(, -5).Column), Cells(cl.Row, Range("curr_zfin").Column))
cl1.Formula = "=Sum(SumIF('[ZFIN.xlsx]" & Cells(Range("curr_zfin").Row, cl1.Column) & "'!$B$7:$B$2500," & Join(arr, ";") & ",'[ZFIN.xlsx]" & Cells(Range("curr_zfin").Row, cl1.Column) & "'!$D$7:$D$2500))"
cl1.Value = cl1.Value * -1
cl1.NumberFormat = "_(* #,##0_);_(* (#,##0);_(* "" - ""??_);_(@_)"
Next cl1
Case Else: For Each cl1 In ws_port.Range(Cells(cl.Row, Range("curr_zfin").Offset(, -5).Column), Cells(cl.Row, Range("curr_zfin").Column))
cl1.Formula = "=IF(ISNA(Vlookup($B" & cl.Row & ",'[ZFIN.xlsx]" & Cells(Range("curr_zfin").Row, cl1.Column) & "'!$B:$L,3,False)),0,Vlookup($B" & cl.Row & ",'[ZFIN.xlsx]" & Cells(Range("curr_zfin").Row, cl1.Column) & "'!$B:$L,3,False))"
cl1.Value = cl1.Value * -1
cl1.NumberFormat = "_(* #,##0_);_(* (#,##0);_(* "" - ""??_);_(@_)"
Next cl1
End Select
'Case 14, 18, 22, 26: Select Case Left(wf.Trim(wf.Clean(LCase(cl))), 2)
'Case "bp", "p1": pc1 = Left(wf.Trim(wf.Clean(LCase(cl))), 10)
'pc2 = Left(wf.Trim(wf.Clean(LCase(cl))), 7) & Mid(cl, 12, 3)
'pc3 = Left(wf.Trim(wf.Clean(LCase(cl))), 7) & Mid(cl, 16, 3)
'pc4 = Left(wf.Trim(wf.Clean(LCase(cl))), 7) & Mid(cl, 20, 3)
'pc5 = Left(wf.Trim(wf.Clean(LCase(cl))), 7) & Mid(cl, 24, 3)
'arr = Array(pc1, pc2, pc3, pc4, pc5)
'For Each cl1 In ws_port.Range(Cells(cl.Row, Range("curr_zfin").Offset(, -5).Column), Cells(cl.Row, Range("curr_zfin").Column))
'cl1.Formula = "=Sum(SumIF('[ZFIN.xlsx]" & Cells(Range("curr_zfin").Row, cl1.Column) & "'!$B$7:$B$2500,{" & Join(arr, ";") & "},'[ZFIN.xlsx]" & Cells(Range("curr_zfin").Row, cl1.Column) & "'!$D$7:$D$2500))"
'cl1.Value = cl1.Value * -1
'cl1.NumberFormat = "_(* #,##0_);_(* (#,##0);_(* "" - ""??_);_(@_)"
'Next cl1
'Case Else: For Each cl1 In ws_port.Range(Cells(cl.Row, Range("curr_zfin").Offset(, -5).Column), Cells(cl.Row, Range("curr_zfin").Column))
'cl1.Formula = "=IF(ISNA(Vlookup($B" & cl.Row & ",'[ZFIN.xlsx]" & Cells(Range("curr_zfin").Row, cl1.Column) & "'!$B:$L,3,False)),0,Vlookup($B" & cl.Row & ",'[ZFIN.xlsx]" & Cells(Range("curr_zfin").Row, cl1.Column) & "'!$B:$L,3,False))"
'cl1.Value = cl1.Value * -1
'cl1.NumberFormat = "_(* #,##0_);_(* (#,##0);_(* "" - ""??_);_(@_)"
'Next cl1
'End Select
Case Else: For Each cl1 In ws_port.Range(Cells(cl.Row, Range("curr_zfin").Offset(, -5).Column), Cells(cl.Row, Range("curr_zfin").Column))
cl1.Formula = "=IF(ISNA(Vlookup($B" & cl.Row & ",'[ZFIN.xlsx]" & Cells(Range("curr_zfin").Row, cl1.Column) & "'!$B:$L,3,False)),0,Vlookup($B" & cl.Row & ",'[ZFIN.xlsx]" & Cells(Range("curr_zfin").Row, cl1.Column) & "'!$B:$L,3,False))"
cl1.Value = cl1.Value * -1
cl1.NumberFormat = "_(* #,##0_);_(* (#,##0);_(* "" - ""??_);_(@_)"
Next cl1
End Select
Next cl
Application.ScreenUpdating = True
wb_zfin.Close SaveChanges:=False
End Sub