microsoft_excel:macro_full_example_program
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
microsoft_excel:macro_full_example_program [2019/12/13 12:02] – created peter | microsoft_excel:macro_full_example_program [2021/08/04 13:59] (current) – removed peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Microsoft Excel - Macro Full Example Program ====== | ||
- | |||
- | <code excel> | ||
- | |||
- | ' Options | ||
- | |||
- | ' Option Explicit forces you to declare all your variables. | ||
- | Option Explicit | ||
- | |||
- | ' Makes all "text comparisons" | ||
- | Option Compare Text | ||
- | |||
- | |||
- | ' | ||
- | |||
- | ' Window API Declarations | ||
- | ' These Declares MUST appear at the top of the code module, above and before any VBA procedures. | ||
- | |||
- | 'Const HWND_BOTTOM = 1 | ||
- | Const SWP_NOSIZE = &H1 | ||
- | Const SWP_NOMOVE = &H2 | ||
- | Const SWP_NOACTIVATE = &H10 | ||
- | Const SWP_SHOWWINDOW = &H40 | ||
- | |||
- | Public Const HWND_TOPMOST = -1 | ||
- | Public Const HWND_NOTOPMOST = -2 | ||
- | Public Const HWND_TOP = 0 | ||
- | Public Const HWND_BOTTOM = 1 | ||
- | |||
- | |||
- | ' http:// | ||
- | ' | ||
- | ' Message boxes are always modal, which means that the underlying application (e.g. Excel) waits for a response from | ||
- | ' the User and does not allow any other interaction until one is given. | ||
- | ' By default they are application modal (they remain in front of all other windows belonging to the owning application | ||
- | ' but have no impact on other applications), | ||
- | ' windows although they have no non-visual impact on applications other than the owning one). | ||
- | ' | ||
- | ' Use the Message Box facility directly, via the Windows API, instead of via the VBA interface. | ||
- | ' Using it is pretty much the same as using MsgBox, except that you have the opportunity to set some parameter values | ||
- | ' which are defaulted in the VBA interface, in particular the message box, although technically still modal, can be | ||
- | ' attached to any window, or none. If you do not attach it to your window, it will not restrict your User's interaction | ||
- | ' with the application. | ||
- | Private Declare Function MessageBox _ | ||
- | Lib " | ||
- | | ||
- | ByVal lpText As String, _ | ||
- | ByVal lpCaption As String, _ | ||
- | ByVal wType As Long) _ | ||
- | As Long | ||
- | |||
- | |||
- | ' Used to have XL be on top of all other windows. | ||
- | #If Win64 Then | ||
- | Public Declare PtrSafe Function SetWindowPos _ | ||
- | Lib " | ||
- | ByVal hwnd As LongPtr, _ | ||
- | ByVal hwndInsertAfter As LongPtr, _ | ||
- | ByVal x As Long, _ | ||
- | ByVal y As Long, _ | ||
- | ByVal cx As Long, _ | ||
- | ByVal cy As Long, _ | ||
- | ByVal wFlags As Long) _ | ||
- | As Long | ||
- | #Else | ||
- | Public Declare Function SetWindowPos _ | ||
- | Lib " | ||
- | ByVal hwnd As Long, _ | ||
- | ByVal hwndInsertAfter As Long, _ | ||
- | ByVal x As Long, _ | ||
- | ByVal y As Long, _ | ||
- | ByVal cx As Long, _ | ||
- | ByVal cy As Long, _ | ||
- | ByVal wFlags As Long) _ | ||
- | As Long | ||
- | #End If | ||
- | |||
- | |||
- | ' | ||
- | |||
- | ' Some public variables. | ||
- | |||
- | Public wb_name As String | ||
- | |||
- | Public ctrl_disable_auto_calcs_before_subroutine As Boolean | ||
- | Public ctrl_reenable_auto_calcs_after_subroutine As Boolean | ||
- | Public ctrl_ask_before_running_subroutine As Boolean | ||
- | Public ctrl_show_dashboard_after_subroutine As Boolean | ||
- | Public ctrl_close_erroneous_files As Boolean | ||
- | Public ctrl_display_sheet_adding_error As Boolean | ||
- | Public ctrl_use_system_modal_messages As Boolean | ||
- | Public ctrl_clear_formatting_as_well As Boolean | ||
- | Public ctrl_processing_type As Long | ||
- | |||
- | |||
- | |||
- | Sub ShowXLOnTop(ByVal OnTop As Boolean) | ||
- | |||
- | Dim xStype As Long | ||
- | |||
- | #If Win64 Then | ||
- | Dim xHwnd As LongPtr | ||
- | #Else | ||
- | Dim xHwnd As Long | ||
- | #End If | ||
- | |||
- | If OnTop Then | ||
- | xStype = HWND_TOPMOST | ||
- | Else | ||
- | xStype = HWND_NOTOPMOST | ||
- | End If | ||
- | | ||
- | Call SetWindowPos(Application.hwnd, | ||
- | | ||
- | End Sub | ||
- | |||
- | |||
- | ' Sets that XL is the top window of all applications. | ||
- | Sub SetXLOnTop() | ||
- | ShowXLOnTop True | ||
- | End Sub | ||
- | |||
- | |||
- | ' Sets that XL is not necessarily the top windows of all applications. | ||
- | ' If this were not run at some stage then no other application, | ||
- | Sub SetXLNormal() | ||
- | ShowXLOnTop False | ||
- | End Sub | ||
- | |||
- | |||
- | ' Scrolls the worksheet to the specific range. | ||
- | ' For instance ScrollTo " | ||
- | Sub ScrollTo(ws As String, rng As String) | ||
- | |||
- | Application.GoTo Worksheets(ws).Range(rng), | ||
- | Worksheets(ws).Range(rng).Select | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | ' Removes AutoFilter if one exists. | ||
- | Sub TurnFilterOffAllSheets() | ||
- | |||
- | Dim ws As Worksheet | ||
- | |||
- | For Each ws In ActiveWorkbook.Worksheets | ||
- | With ws | ||
- | .AutoFilterMode = False | ||
- | End With | ||
- | Next ws | ||
- | | ||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Delete all unused blank rows and columns in the sheet. | ||
- | ' Note: This code may not work correctly if the worksheet contains merged cells. | ||
- | Sub DeleteUnusedOnSheet(ws As String) | ||
- | |||
- | Dim myLastRow As Long | ||
- | Dim myLastCol As Long | ||
- | Dim wks As Worksheet | ||
- | |||
- | With Worksheets(ws) | ||
- | myLastRow = 0 | ||
- | myLastCol = 0 | ||
- | On Error Resume Next | ||
- | myLastRow = _ | ||
- | .Cells.Find(" | ||
- | LookIn: | ||
- | searchdirection: | ||
- | searchorder: | ||
- | myLastCol = _ | ||
- | .Cells.Find(" | ||
- | LookIn: | ||
- | searchdirection: | ||
- | searchorder: | ||
- | On Error GoTo 0 | ||
- | |||
- | If myLastRow * myLastCol = 0 Then | ||
- | .Columns.Delete | ||
- | Else | ||
- | .Range(.Cells(myLastRow + 1, 1), _ | ||
- | .Cells(.Rows.Count, | ||
- | .Range(.Cells(1, | ||
- | .Cells(1, .Columns.Count)).EntireColumn.Delete | ||
- | End If | ||
- | End With | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | ' Displays a message to the user, optionally adding in how long the process ran and the queryname. | ||
- | ' Depending on the Developer Control settings it will display a System modal message. | ||
- | Function Message(msg As String, Optional elapsedtime As Single, Optional queryname As String) | ||
- | |||
- | Dim msg_to_show As String | ||
- | | ||
- | msg_to_show = msg | ||
- | | ||
- | | ||
- | If Not IsMissing(elapsedtime) And elapsedtime > 0 Then | ||
- | If msg_to_show <> "" | ||
- | msg_to_show = msg_to_show & vbCrLf & vbCrLf | ||
- | End If | ||
- | | ||
- | If Not IsMissing(queryname) Then | ||
- | msg_to_show = msg_to_show & "The query """ | ||
- | & " seconds to run." | ||
- | Else | ||
- | msg_to_show = msg_to_show & "The query took " & elapsedtime & " seconds to run." | ||
- | End If | ||
- | End If | ||
- | | ||
- | If ctrl_use_system_modal_messages = True Then | ||
- | If Not IsMissing(queryname) Then | ||
- | MessageBox &H0, msg_to_show, | ||
- | Else | ||
- | MessageBox &H0, msg_to_show, | ||
- | End If | ||
- | Else | ||
- | MsgBox msg_to_show | ||
- | End If | ||
- | | ||
- | End Function | ||
- | |||
- | |||
- | |||
- | |||
- | ' Initializes global variables. | ||
- | ' These variables are set within the " | ||
- | Sub Z00000_Init() | ||
- | |||
- | ' Set a shortcut to the workbook. | ||
- | wb_name = ThisWorkbook.name | ||
- | |||
- | |||
- | ' Set public variables from the Developer Control Sheet. | ||
- | ctrl_disable_auto_calcs_before_subroutine = Workbooks(wb_name).Sheets(" | ||
- | ctrl_reenable_auto_calcs_after_subroutine = Workbooks(wb_name).Sheets(" | ||
- | ctrl_ask_before_running_subroutine = Workbooks(wb_name).Sheets(" | ||
- | |||
- | ctrl_show_dashboard_after_subroutine = Workbooks(wb_name).Sheets(" | ||
- | ctrl_close_erroneous_files = Workbooks(wb_name).Sheets(" | ||
- | ctrl_display_sheet_adding_error = Workbooks(wb_name).Sheets(" | ||
- | ctrl_use_system_modal_messages = Workbooks(wb_name).Sheets(" | ||
- | ctrl_clear_formatting_as_well = Workbooks(wb_name).Sheets(" | ||
- | ctrl_processing_type = Workbooks(wb_name).Sheets(" | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Runs whichever subroutine name is passed to it. | ||
- | ' This is the ' | ||
- | Sub Z99999_Run_Subroutine(strQueryName As String, Optional strDescription As String = "" | ||
- | |||
- | Dim sngStart As Single | ||
- | Dim sngEnd As Single | ||
- | Dim sngElapsed As Single | ||
- | |||
- | ' Control to prevent user from overwriting the template. | ||
- | If ThisWorkbook.name Like "* Template.xlsm" | ||
- | MsgBox "This workbook is the template, you must not make changes to it." & vbCrLf & vbCrLf & "You need to save as a new workbook name before running any macros." | ||
- | Exit Sub | ||
- | End If | ||
- | |||
- | |||
- | ' Get start time. | ||
- | sngStart = Timer | ||
- | | ||
- | | ||
- | ' Initializes global variables. | ||
- | Call Z00000_Init | ||
- | |||
- | | ||
- | ' To speed up processing. | ||
- | If ctrl_disable_auto_calcs_before_subroutine Then | ||
- | With Application | ||
- | .Calculation = xlCalculationManual | ||
- | .EnableEvents = False | ||
- | .ScreenUpdating = False | ||
- | End With | ||
- | End If | ||
- | | ||
- | | ||
- | ' Turn filters off on all sheets. | ||
- | Call TurnFilterOffAllSheets | ||
- | | ||
- | | ||
- | ' Update StatusBar message. | ||
- | If strDescription = "" | ||
- | Application.StatusBar = " | ||
- | Else | ||
- | Application.StatusBar = " | ||
- | End If | ||
- | | ||
- | | ||
- | ' Run query. | ||
- | ' | ||
- | 'Call strQueryName | ||
- | Application.Run strQueryName | ||
- | | ||
- | | ||
- | ' Re-enable automatic calculations. | ||
- | If ctrl_reenable_auto_calcs_after_subroutine Then | ||
- | With Application | ||
- | .Calculation = xlCalculationAutomatic | ||
- | .EnableEvents = True | ||
- | .ScreenUpdating = True | ||
- | End With | ||
- | End If | ||
- | | ||
- | |||
- | ' Activate the dashboard. | ||
- | If ctrl_show_dashboard_after_subroutine Then | ||
- | Workbooks(wb_name).Sheets(" | ||
- | End If | ||
- | |||
- | | ||
- | ' Display how long the subroutine ran for. | ||
- | sngEnd = Timer ' | ||
- | sngElapsed = Format(sngEnd - sngStart, " | ||
- | |||
- | |||
- | ' Make excel top most to bring it to the top of other applications. | ||
- | SetXLOnTop | ||
- | | ||
- | | ||
- | ' Display message to user. | ||
- | If strDescription = "" | ||
- | Message "", | ||
- | Application.StatusBar = " | ||
- | Else | ||
- | Message "", | ||
- | Application.StatusBar = " | ||
- | End If | ||
- | | ||
- | | ||
- | ' Make excel not top most to allow other applications to go on top of it. | ||
- | SetXLNormal | ||
- | | ||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Runs the M10000_Clear_All subroutine. | ||
- | ' Clears all sheets, but leaves the forumulas which are in the 2nd row on most sheets. | ||
- | Sub Run_M10000_Clear_All() | ||
- | |||
- | Call Z99999_Run_Subroutine(" | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | ' Runs the M10030_Reset_Formulae subroutine. | ||
- | ' Writes all formulae into the 2nd row on all sheets. | ||
- | ' Usually the green column headings indicate which have formulae. | ||
- | Sub Run_M10030_Reset_Formulae() | ||
- | |||
- | Call Z99999_Run_Subroutine(" | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | ' Runs the M10040_Refresh_Queries subroutine. | ||
- | ' Refreshes all queries on all sheets. | ||
- | Sub Run_M10040_Refresh_Queries() | ||
- | |||
- | Call Z99999_Run_Subroutine(" | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | ' Runs the M10100_Import_FinalABC subroutine. | ||
- | ' Imports the FinalABC file. | ||
- | Sub Run_M10100_Import_FinalABC() | ||
- | |||
- | Call Z99999_Run_Subroutine(" | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | ' Runs the M10110_Copy_Pre_FinalABC_Formulae_Down subroutine. | ||
- | ' Copy initial formulae down on the FinalABC sheet. | ||
- | ' Just enough data to allow the sheet to be later sorted and for the Mapping Pivots to be created. | ||
- | Sub Run_M10110_Copy_Pre_FinalABC_Formulae_Down() | ||
- | |||
- | Call Z99999_Run_Subroutine(" | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Runs the M10120_Sort_FinalABC_column_A subroutine. | ||
- | ' Sort FinalABC on column A in ascending order. | ||
- | Sub Run_M10120_Sort_FinalABC_column_A() | ||
- | |||
- | Call Z99999_Run_Subroutine(" | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Runs the M10200_Refresh_Mapping_Pivots subroutine. | ||
- | ' Refresh the Mapping Pivots. | ||
- | ' These only depend on the FinalABC sheet. | ||
- | Sub Run_M10200_Refresh_Mapping_Pivots() | ||
- | |||
- | Call Z99999_Run_Subroutine(" | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Runs the M10300_Import_SHEETNAME1_from_Auto subroutine. | ||
- | ' Import data into the SHEETNAME1 sheet from the " | ||
- | ' The " | ||
- | Sub Run_M10300_Import_SHEETNAME1_from_Auto() | ||
- | |||
- | Call Z99999_Run_Subroutine(" | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | ' Runs the M10300_Import_SHEETNAME1 subroutine. | ||
- | ' Filename must be in the format SHEETNAME1CCYYMMDD.csv. | ||
- | ' If not MMDD available then use 9999 in their place. | ||
- | Sub Run_M10300_Import_SHEETNAME1() | ||
- | |||
- | Call Z99999_Run_Subroutine(" | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Runs the M10400_Update_FinalABC_Formulae subroutine. | ||
- | ' Updates the formulae on the FinalABC sheet to only reference the specific number of rows actually loaded into the | ||
- | ' FinalABC sheet instead of something like A:A which would reference over 1 million rows and therefore may slow down | ||
- | ' calculations etc. | ||
- | Sub Run_M10400_Update_FinalABC_Formulae() | ||
- | |||
- | Call Z99999_Run_Subroutine(" | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Runs the M10410_Copy_Post_FinalABC_Formulae_Down subroutine. | ||
- | ' Copy the updated formula on the FinalABC sheet down for all populated rows. | ||
- | Sub Run_M10410_Copy_Post_FinalABC_Formulae_Down() | ||
- | |||
- | Select Case ctrl_processing_type | ||
- | | ||
- | Case 1 | ||
- | Call Z99999_Run_Subroutine(" | ||
- | | ||
- | Case 2 | ||
- | Call Z99999_Run_Subroutine(" | ||
- | | ||
- | Case Else | ||
- | Call Z99999_Run_Subroutine(" | ||
- | | ||
- | End Select | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Runs the M10500_Copy_Pre_SHEETNAME1_Formulae_Down subroutine. | ||
- | ' Copy pre SHEETNAME1 formula down. | ||
- | ' Just enough data to allow SHEETNAME1 sheet to be sorted. | ||
- | Sub Run_M10500_Copy_Pre_SHEETNAME1_Formulae_Down() | ||
- | |||
- | Select Case ctrl_processing_type | ||
- | | ||
- | Case 1 | ||
- | Call Z99999_Run_Subroutine(" | ||
- | | ||
- | Case 2 | ||
- | Call Z99999_Run_Subroutine(" | ||
- | | ||
- | Case Else | ||
- | Call Z99999_Run_Subroutine(" | ||
- | | ||
- | End Select | ||
- | | ||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Runs the M10510_Sort_SHEETNAME1_column_A subroutine. | ||
- | ' Sorts the SHEETNAME1 sheet by Column A and M in ascending order. | ||
- | Sub Run_M10510_Sort_SHEETNAME1_column_A() | ||
- | |||
- | Call Z99999_Run_Subroutine(" | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Runs the M10520_Update_SHEETNAME1_Formulae subroutine. | ||
- | ' Updates the formulae on the SHEETNAME1 sheet to only reference the specific number of rows actually loaded into the SHEETNAME1 sheet | ||
- | ' instead of something like A:A which would reference over 1 million rows and therefore may slow down calculations etc. | ||
- | Sub Run_M10520_Update_SHEETNAME1_Formulae() | ||
- | |||
- | Select Case ctrl_processing_type | ||
- | | ||
- | Case 1 | ||
- | Call Z99999_Run_Subroutine(" | ||
- | | ||
- | Case 2 | ||
- | Call Z99999_Run_Subroutine(" | ||
- | | ||
- | Case Else | ||
- | Call Z99999_Run_Subroutine(" | ||
- | | ||
- | End Select | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Runs the M10535_Copy_Post_SHEETNAME1_Formulae_Down_Array subroutine. | ||
- | ' Speedy - copies using arrays. | ||
- | ' Copies remaining formulae down on the SHEETNAME1 sheet. | ||
- | Sub Run_M10535_Copy_Post_SHEETNAME1_Formulae_Down_Array() | ||
- | |||
- | Call Z99999_Run_Subroutine(" | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Runs the M10540_Copy_Post_SHEETNAME1_Formulae_Down subroutine. | ||
- | ' Copies remaining formulae down on the SHEETNAME1 sheet. | ||
- | Sub Run_M10540_Copy_Post_SHEETNAME1_Formulae_Down() | ||
- | |||
- | Select Case ctrl_processing_type | ||
- | | ||
- | Case 1 | ||
- | Call Z99999_Run_Subroutine(" | ||
- | | ||
- | Case 2 | ||
- | Call Z99999_Run_Subroutine(" | ||
- | | ||
- | Case Else | ||
- | Call Z99999_Run_Subroutine(" | ||
- | | ||
- | End Select | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Runs the M10600_Copy_More_FinalABC_Formulae_Down subroutine. | ||
- | ' Now that both Final and SHEETNAME1 sheets populated, need to action some more formula calculations. | ||
- | Sub Run_M10600_Copy_More_FinalABC_Formulae_Down() | ||
- | |||
- | Call Z99999_Run_Subroutine(" | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Runs the M10610_Reformat_FinalABC_Corrected_Dates subroutine. | ||
- | ' Adds 1 to the Corrected Date, column E, in the FinalABC sheet for dates that were the last date of the month. | ||
- | ' It then recalculates the sheet to determine if column AJ now reconciles, i.e. shows " | ||
- | ' This requires the following columns to have formulae throughout: | ||
- | Sub Run_M10610_Reformat_FinalABC_Corrected_Dates() | ||
- | |||
- | Call Z99999_Run_Subroutine(" | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Runs the M10620_Recalc_SHEETNAME1_Formulae subroutine. | ||
- | ' Copies remaining formulae down on the SHEETNAME1 sheet. | ||
- | Sub Run_M10620_Recalc_SHEETNAME1_Formulae() | ||
- | |||
- | Select Case ctrl_processing_type | ||
- | | ||
- | Case 1 | ||
- | Call Z99999_Run_Subroutine(" | ||
- | | ||
- | Case 2 | ||
- | Call Z99999_Run_Subroutine(" | ||
- | | ||
- | Case Else | ||
- | Call Z99999_Run_Subroutine(" | ||
- | | ||
- | End Select | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | ' Runs the M10700_Format_FinalABC_lines subroutine. | ||
- | ' Format the FinalABC sheet to put lines between ISINs. | ||
- | Sub Run_M10700_Format_FinalABC_lines() | ||
- | |||
- | Call Z99999_Run_Subroutine(" | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Runs the M10710_Format_SHEETNAME1_Lines subroutine. | ||
- | ' Format the SHEETNAME1 sheet by placing lines between ISINs. | ||
- | Sub Run_M10710_Format_SHEETNAME1_Lines() | ||
- | |||
- | Call Z99999_Run_Subroutine(" | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Runs the M10800_Refresh_Rec_Dashboard_Pivots subroutine. | ||
- | ' Refresh the PIVOT tables on the REC DASHBOARD sheet. | ||
- | Sub Run_M10800_Refresh_Rec_Dashboard_Pivots() | ||
- | |||
- | Call Z99999_Run_Subroutine(" | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Runs the M10810_Refresh_Adj_Dashboard_Pivots subroutine. | ||
- | ' Refresh the PIVOT tables on the ADJ DASHBOARD sheet. | ||
- | Sub Run_M10810_Refresh_Adj_Dashboard_Pivots() | ||
- | |||
- | Call Z99999_Run_Subroutine(" | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Runs the M10910_Revert_Reformatted_FinalABC_Corrected_Dates subroutine. | ||
- | ' Reverts the Corrected Date, column E, in the FinalABC sheet back to its original calculated date. | ||
- | ' It only does this for cells where column AJ does not still reconciles, i.e. does not show " | ||
- | ' This requires the following columns to have formulae throughout: | ||
- | Sub Run_M10910_Revert_Reformatted_FinalABC_Corrected_Dates() | ||
- | |||
- | Call Z99999_Run_Subroutine(" | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | ' Runs the M11000_Clear_SHEETNAME1_lines subroutine. | ||
- | ' Clears formatting on the SHEETNAME1 sheet. | ||
- | ' Removes the lines between ISINs. | ||
- | Sub Run_M11000_Clear_SHEETNAME1_lines() | ||
- | |||
- | Call Z99999_Run_Subroutine(" | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | ' Runs the M1110_Clear_FinalABC_lines subroutine. | ||
- | ' Clears formatting on the FinalABC sheet. | ||
- | Sub Run_M11110_Clear_FinalABC_lines() | ||
- | |||
- | Call Z99999_Run_Subroutine(" | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | ' Runs the M11200_Recalc_changed_adjusted_rows subroutine. | ||
- | ' For any row that has adjusted values different than the original value it recalculates the values against that row. | ||
- | ' It does this by putting formulae back in only for the specific row and then performing the recalc. | ||
- | ' Later the formula are replaced by values again. | ||
- | Sub Run_M11200_Recalc_changed_adjusted_rows() | ||
- | |||
- | Select Case ctrl_processing_type | ||
- | | ||
- | Case 1 | ||
- | | ||
- | Call Z99999_Run_Subroutine(" | ||
- | 'Call Z99999_Run_Subroutine(" | ||
- | | ||
- | Case 2 | ||
- | Call Z99999_Run_Subroutine(" | ||
- | | ||
- | Case Else | ||
- | Call Z99999_Run_Subroutine(" | ||
- | | ||
- | End Select | ||
- | |||
- | |||
- | End Sub | ||
- | |||
- | |||
- | ' Runs the M11207_Recalc_changed_adjusted_rows subroutine. | ||
- | ' This prompt the user for a row in the SHEETNAME1 sheet. | ||
- | ' It then recalculates the values against that row. | ||
- | ' It does this by putting formulae back in only for the specific row and then performing the recalc. | ||
- | ' Later the formula are replaced by values again. | ||
- | Sub Run_M11207_Recalc_changed_adjusted_rows() | ||
- | |||
- | Call Z99999_Run_Subroutine(" | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | ' Runs the M11208_Recalc_changed_adjusted_rows subroutine. | ||
- | ' This prompt the user for a row in the FinalABC sheet. | ||
- | ' It then recalculates the values against that row. | ||
- | ' It does this by putting formulae back in only for the specific row and then performing the recalc. | ||
- | ' Later the formula are replaced by values again. | ||
- | Sub Run_M11208_Recalc_changed_adjusted_rows() | ||
- | |||
- | Call Z99999_Run_Subroutine(" | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | ' Runs the M12000_Copy_FinalABC_Formulae_Down subroutine. | ||
- | ' Copies all formulae down on the FinalABC sheet. | ||
- | ' Does not change the formula to values. | ||
- | ' Does not calculate. | ||
- | ' This may run for a very long time. Go have a coffee. | ||
- | Sub Run_M12000_Copy_FinalABC_Formulae_Down() | ||
- | |||
- | Call Z99999_Run_Subroutine(" | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Runs the M12010_Convert_FinalABC_Formulae_to_Values subroutine. | ||
- | ' Converts all formulae on the FinalABC sheet to Values. | ||
- | ' Does not change row 2 of the FinalABC sheet. | ||
- | ' This may run for a very long time. Go have a coffee. | ||
- | Sub Run_M12010_Convert_FinalABC_Formulae_to_Values() | ||
- | |||
- | Call Z99999_Run_Subroutine(" | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Runs the M12020_Copy_SHEETNAME1_Formulae_Down subroutine. | ||
- | ' Copies down all formulae on the SHEETNAME1 sheet. | ||
- | ' Does not change the formula to values. | ||
- | ' Does not calculate. | ||
- | ' This may run for a very long time. Go have a coffee. | ||
- | Sub Run_M12020_Copy_SHEETNAME1_Formulae_Down() | ||
- | |||
- | Call Z99999_Run_Subroutine(" | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Runs the M12030_Convert_SHEETNAME1_Formulae_to_Values subroutine. | ||
- | ' Converts all formula cells on the SHEETNAME1 sheet into values. | ||
- | ' Does not change row 2 of the SHEETNAME1 sheet. | ||
- | ' This may run for a very long time. Go have a coffee. | ||
- | Sub Run_M12030_Convert_SHEETNAME1_Formulae_to_Values() | ||
- | |||
- | Call Z99999_Run_Subroutine(" | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Runs the M13000_Import_Wxxxx subroutine. | ||
- | ' Imports the Wxxxx file into the Wxxxx tab. | ||
- | ' This also sorts the result and places in formulas. | ||
- | Sub Run_M13000_Import_Wxxxx() | ||
- | |||
- | Call Z99999_Run_Subroutine(" | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Clears all sheets, but leaves the formulae which are in the 2nd row on most sheets. | ||
- | Sub M10000_Clear_All() | ||
- | |||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | |||
- | |||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | ' Clear the SHEETNAME1 sheet. | ||
- | Call M10010_Clear_SHEETNAME1 | ||
- | | ||
- | | ||
- | ' Clear the FinalABC sheet. | ||
- | Call M10020_Clear_FinalABC | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Clears the SHEETNAME1 sheet, but leaves the formulae which are in the 2nd row. | ||
- | Sub M10010_Clear_SHEETNAME1() | ||
- | |||
- | Dim lastrow_SHEETNAME1 As Long ' Last row in the SHEETNAME1 sheet | ||
- | Dim rng As Range | ||
- | Dim i As Long | ||
- | |||
- | |||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | |||
- | |||
- | ' Ask user. | ||
- | 'If ctrl_ask_before_running_subroutine = True Then | ||
- | ' | ||
- | 'End If | ||
- | | ||
- | | ||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_SHEETNAME1 = .Cells(Rows.Count, | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_SHEETNAME1 < 3 Then | ||
- | lastrow_SHEETNAME1 = 3 | ||
- | End If | ||
- | |||
- | |||
- | ' Set entire range to blank. | ||
- | Set rng = .Range(" | ||
- | rng.Value = "" | ||
- | |||
- | |||
- | ' Clear entire sheet, except for row 2 which contains formulae. | ||
- | ' Uses ClearContents instead of Delete as much quicker. | ||
- | ' ClearContents only clears the cell value and not the formatting if any. | ||
- | For i = lastrow_SHEETNAME1 To 3 Step -1 | ||
- | .Rows(i).ClearContents | ||
- | Next i | ||
- | |||
- | |||
- | ' Clear fields loaded from SHEETNAME1 file. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Clear formatting. | ||
- | If ctrl_clear_formatting_as_well = True Then | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | End If | ||
- | | ||
- | | ||
- | ' Clear any double lines. | ||
- | .Range(" | ||
- | |||
- | |||
- | ' Reset font to standard. | ||
- | .Range(" | ||
- | |||
- | |||
- | ' Delete all unused rows and columns in the sheet. | ||
- | DeleteUnusedOnSheet (" | ||
- | | ||
- | End With | ||
- | End With | ||
- | |||
- | |||
- | ' Do calculation. | ||
- | With Application | ||
- | .Calculate | ||
- | End With | ||
- | |||
- | |||
- | ' Clear all objects. | ||
- | Set rng = Nothing | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Clears the FinalABC sheet, but leaves the formulae which are in the 2nd row. | ||
- | Sub M10020_Clear_FinalABC() | ||
- | |||
- | Dim lastrow_FinalABC As Long ' Last row in the FinalABC sheet | ||
- | Dim rng As Range | ||
- | |||
- | |||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | |||
- | |||
- | ' Ask user. | ||
- | 'If ctrl_ask_before_running_subroutine = True Then | ||
- | ' | ||
- | 'End If | ||
- | |||
- | | ||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | |||
- | | ||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_FinalABC = .Cells(Rows.Count, | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_FinalABC < 3 Then | ||
- | lastrow_FinalABC = 3 | ||
- | End If | ||
- | | ||
- | | ||
- | ' Clear entire sheet, except for row 2 which contains formulae. | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Clear fields loaded from BBH file. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Clear formatting. | ||
- | If ctrl_clear_formatting_as_well = True Then | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | End If | ||
- | | ||
- | | ||
- | ' Clear any double lines. | ||
- | .Range(" | ||
- | |||
- | | ||
- | ' Reset font to standard. | ||
- | .Range(" | ||
- | |||
- | | ||
- | ' This deletes empty rows at the bottom of the sheet. | ||
- | ' This substantially reduces the size of the sheet, especially in larger Excel sheets going down to over 1 Million rows. | ||
- | ' | ||
- | | ||
- | | ||
- | ' Delete all unused black rows and columns in the sheet. | ||
- | DeleteUnusedOnSheet (" | ||
- | | ||
- | | ||
- | ' Control to confirm there is currently no data in the blue columns in the FinalABC sheet. | ||
- | If WorksheetFunction.CountA( _ | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | Message "There is data still present in the blue columns in the FinalABC sheet, these should be blank. Ensure they are empty before running this process." | ||
- | Exit Sub | ||
- | End If | ||
- | | ||
- | End With | ||
- | End With | ||
- | |||
- | |||
- | ' Do calculation. | ||
- | With Application | ||
- | .Calculate | ||
- | End With | ||
- | |||
- | |||
- | ' Clear all objects. | ||
- | Set rng = Nothing | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Writes all formulae into the 2nd row on all sheets. | ||
- | ' Usually the green column headings indicate which have formulae. | ||
- | Sub M10030_Reset_Formulae() | ||
- | |||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | |||
- | | ||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | |||
- | ' Resets formulae on TRANSACTIONS. | ||
- | 'With .Sheets(" | ||
- | ' | ||
- | ' | ||
- | 'End With | ||
- | |||
- | ' Resets formulae on SHEETNAME1. | ||
- | With .Sheets(" | ||
- | .Activate | ||
- | | ||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | End With | ||
- | |||
- | |||
- | ' Resets formulae on FinalABC. | ||
- | With .Sheets(" | ||
- | .Activate | ||
- | | ||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | End With | ||
- | |||
- | |||
- | ' Resets formulae on References. | ||
- | ' These are hard-coded for various rows as small in number. | ||
- | With .Sheets(" | ||
- | .Activate | ||
- | | ||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | End With | ||
- | |||
- | |||
- | ' Resets formulae on QSHEET. | ||
- | With .Sheets(" | ||
- | .Activate | ||
- | | ||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | | ||
- | .Range(" | ||
- | End With | ||
- | |||
- | |||
- | ' Resets formulae on " | ||
- | With .Sheets(" | ||
- | .Activate | ||
- | | ||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | End With | ||
- | End With | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Refreshes all queries on all sheets. | ||
- | Sub M10040_Refresh_Queries() | ||
- | |||
- | Dim cn As WorkbookConnection | ||
- | |||
- | |||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | |||
- | | ||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | ' First, ensure that the queries do not run in the background. | ||
- | ' The queries need to really complete before we continue with the next subroutines. | ||
- | For Each cn In ThisWorkbook.Connections | ||
- | If cn.Type = xlConnectionTypeODBC Then | ||
- | cn.ODBCConnection.BackgroundQuery = False | ||
- | End If | ||
- | | ||
- | If cn.Type = xlConnectionTypeOLEDB Then | ||
- | cn.OLEDBConnection.BackgroundQuery = False | ||
- | End If | ||
- | | ||
- | | ||
- | ' Update status message. | ||
- | Application.StatusBar = " | ||
- | |||
- | | ||
- | ' Refresh the query. | ||
- | cn.Refresh | ||
- | Next cn | ||
- | |||
- | |||
- | ' Call Sort_Queries | ||
- | Call M10050_Sort_Queries | ||
- | | ||
- | |||
- | ' Clear all variables. | ||
- | Set cn = Nothing | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | ' Sorts all queries on all sheets. | ||
- | ' Unfortunately, | ||
- | Sub M10050_Sort_Queries() | ||
- | |||
- | Dim lastrow_SHEETNAME1Auto As Long | ||
- | Dim lastrow_CUST As Long | ||
- | Dim lastrow_HOLDINGS As Long | ||
- | Dim lastrow_QSHEET As Long | ||
- | Dim lastrow_SECT As Long | ||
- | Dim lastrow_TRANSACTIONS As Long | ||
- | Dim lastrow_Wxxxx As Long | ||
- | | ||
- | | ||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | |||
- | | ||
- | ' Ask user. | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | |||
- | |||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activates the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | | ||
- | | ||
- | ' Determine the number of rows. | ||
- | lastrow_SECT = .Cells(Rows.Count, | ||
- | | ||
- | |||
- | ' Do the sort. | ||
- | With .Sort | ||
- | | ||
- | ' | ||
- | With .SortFields | ||
- | .Clear | ||
- | .Add Key: | ||
- | End With | ||
- | | ||
- | .SetRange Range(" | ||
- | .Header = xlYes | ||
- | .MatchCase = False | ||
- | .Orientation = xlTopToBottom | ||
- | .SortMethod = xlPinYin | ||
- | .Apply | ||
- | | ||
- | End With | ||
- | |||
- | |||
- | ' Select A1. | ||
- | ScrollTo ActiveSheet.name, | ||
- | |||
- | End With | ||
- | | ||
- | | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activates the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | | ||
- | | ||
- | ' Determine the number of rows. | ||
- | lastrow_TRANSACTIONS = .Cells(Rows.Count, | ||
- | | ||
- | |||
- | ' Do the sort. | ||
- | With .Sort | ||
- | | ||
- | ' | ||
- | With .SortFields | ||
- | .Clear | ||
- | .Add Key: | ||
- | End With | ||
- | | ||
- | .SetRange Range(" | ||
- | .Header = xlYes | ||
- | .MatchCase = False | ||
- | .Orientation = xlTopToBottom | ||
- | .SortMethod = xlPinYin | ||
- | .Apply | ||
- | | ||
- | End With | ||
- | |||
- | |||
- | ' Select A1. | ||
- | ScrollTo ActiveSheet.name, | ||
- | |||
- | End With | ||
- | | ||
- | | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activates the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | | ||
- | | ||
- | ' Determine the number of rows. | ||
- | lastrow_HOLDINGS = .Cells(Rows.Count, | ||
- | | ||
- | |||
- | ' Do the sort. | ||
- | With .Sort | ||
- | | ||
- | ' | ||
- | With .SortFields | ||
- | .Clear | ||
- | .Add Key: | ||
- | End With | ||
- | | ||
- | .SetRange Range(" | ||
- | .Header = xlYes | ||
- | .MatchCase = False | ||
- | .Orientation = xlTopToBottom | ||
- | .SortMethod = xlPinYin | ||
- | .Apply | ||
- | | ||
- | End With | ||
- | |||
- | |||
- | ' Select A1. | ||
- | ScrollTo ActiveSheet.name, | ||
- | |||
- | End With | ||
- | | ||
- | | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activates the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | | ||
- | | ||
- | ' Determine the number of rows. | ||
- | lastrow_CUST = .Cells(Rows.Count, | ||
- | | ||
- | |||
- | ' Do the sort. | ||
- | With .Sort | ||
- | | ||
- | ' | ||
- | With .SortFields | ||
- | .Clear | ||
- | .Add Key: | ||
- | End With | ||
- | | ||
- | .SetRange Range(" | ||
- | .Header = xlYes | ||
- | .MatchCase = False | ||
- | .Orientation = xlTopToBottom | ||
- | .SortMethod = xlPinYin | ||
- | .Apply | ||
- | | ||
- | End With | ||
- | |||
- | |||
- | ' Select A1. | ||
- | ScrollTo ActiveSheet.name, | ||
- | |||
- | End With | ||
- | | ||
- | | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activates the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | | ||
- | | ||
- | ' Determine the number of rows. | ||
- | lastrow_SHEETNAME1Auto = .Cells(Rows.Count, | ||
- | | ||
- | |||
- | ' Do the sort. | ||
- | With .Sort | ||
- | | ||
- | ' | ||
- | With .SortFields | ||
- | .Clear | ||
- | .Add Key: | ||
- | End With | ||
- | | ||
- | .SetRange Range(" | ||
- | .Header = xlYes | ||
- | .MatchCase = False | ||
- | .Orientation = xlTopToBottom | ||
- | .SortMethod = xlPinYin | ||
- | .Apply | ||
- | | ||
- | End With | ||
- | |||
- | |||
- | ' Select A1. | ||
- | ScrollTo ActiveSheet.name, | ||
- | |||
- | End With | ||
- | | ||
- | | ||
- | |||
- | With .Sheets(" | ||
- | | ||
- | ' Activates the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | | ||
- | | ||
- | ' Determine the number of rows. | ||
- | lastrow_QSHEET = .Cells(Rows.Count, | ||
- | | ||
- | |||
- | ' Do the sort. | ||
- | With .Sort | ||
- | | ||
- | ' | ||
- | With .SortFields | ||
- | .Clear | ||
- | ' PETER-FIX 20191211 | ||
- | .Add Key: | ||
- | End With | ||
- | | ||
- | ' PETER-FIX 20191211 .SetRange Range(" | ||
- | .SetRange Range(" | ||
- | .Header = xlYes | ||
- | .MatchCase = False | ||
- | .Orientation = xlTopToBottom | ||
- | .SortMethod = xlPinYin | ||
- | .Apply | ||
- | | ||
- | End With | ||
- | |||
- | |||
- | ' Select A1. | ||
- | ScrollTo ActiveSheet.name, | ||
- | |||
- | End With | ||
- | | ||
- | | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activates the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | | ||
- | | ||
- | ' Determine the number of rows. | ||
- | lastrow_Wxxxx = .Cells(Rows.Count, | ||
- | | ||
- | |||
- | ' Do the sort. | ||
- | With .Sort | ||
- | | ||
- | ' | ||
- | With .SortFields | ||
- | .Clear | ||
- | .Add Key: | ||
- | End With | ||
- | | ||
- | ' PETER-FIX 20191211. .SetRange Range(" | ||
- | .SetRange Range(" | ||
- | .Header = xlYes | ||
- | .MatchCase = False | ||
- | .Orientation = xlTopToBottom | ||
- | .SortMethod = xlPinYin | ||
- | .Apply | ||
- | | ||
- | End With | ||
- | |||
- | |||
- | ' Select A1. | ||
- | ScrollTo ActiveSheet.name, | ||
- | |||
- | End With | ||
- | | ||
- | End With | ||
- | End Sub | ||
- | |||
- | |||
- | |||
- | |||
- | ' Imports the FinalABC file. | ||
- | |||
- | |||
- | ' Imports the FinalABC file. | ||
- | Sub M10100_Import_FinalABC() | ||
- | |||
- | Dim fileToOpen As Variant | ||
- | Dim count_FinalABC As Double | ||
- | Dim count_InputFile As Double | ||
- | Dim lastrow_FinalABC As Long | ||
- | Dim lastrow_InputFile As Long | ||
- | Dim my_from_column As Variant | ||
- | Dim my_to_column As Variant | ||
- | Dim fileToOpen_name As String | ||
- | Dim FileParts() As String | ||
- | |||
- | |||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | |||
- | |||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | ' Clear the FinalABC sheet. | ||
- | Call M10020_Clear_FinalABC | ||
- | |||
- | |||
- | ' Ask user for a FinalABC file to load. | ||
- | fileToOpen = Application.GetOpenFilename(" | ||
- | If fileToOpen = False Then | ||
- | MsgBox "No BBH file selected. | ||
- | Exit Sub | ||
- | End If | ||
- | | ||
- | FileParts() = Split(fileToOpen, | ||
- | fileToOpen_name = FileParts(UBound(FileParts)) | ||
- | |||
- | |||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | |||
- | |||
- | ' Start of copying columns across. | ||
- | With Workbooks.Open(fileToOpen) | ||
- | | ||
- | With .Sheets(1) | ||
- | |||
- | ' Control to check that the FinalABC file is in the usual format. | ||
- | If .Range(" | ||
- | Else | ||
- | | ||
- | If ctrl_close_erroneous_files = True Then | ||
- | ' Close the file. | ||
- | Application.DisplayAlerts = False | ||
- | Workbooks(fileToOpen_name).Close | ||
- | Application.DisplayAlerts = True | ||
- | End If | ||
- | | ||
- | MsgBox "The FinalABC file is not in the usual format, it may have been change since the code was written, please follow the procedure to manually copy the columns across." | ||
- | Exit Sub | ||
- | End If | ||
- | | ||
- | ' Control to check that the FinalABC file is in the usual format. | ||
- | If .Range(" | ||
- | Else | ||
- | If ctrl_close_erroneous_files = True Then | ||
- | ' Close the file. | ||
- | Application.DisplayAlerts = False | ||
- | Workbooks(fileToOpen_name).Close | ||
- | Application.DisplayAlerts = True | ||
- | End If | ||
- | | ||
- | MsgBox "The FinalABC file is not in the usual format, it may have been change since the code was written, please follow the procedure to manually copy the columns across" | ||
- | Exit Sub | ||
- | End If | ||
- | | ||
- | | ||
- | ' Control to check that the FinalABC file is in the usual format. | ||
- | If WorksheetFunction.CountA(.Range(" | ||
- | Else | ||
- | If ctrl_close_erroneous_files = True Then | ||
- | ' Close the file. | ||
- | Application.DisplayAlerts = False | ||
- | Workbooks(fileToOpen_name).Close | ||
- | Application.DisplayAlerts = True | ||
- | End If | ||
- | | ||
- | MsgBox "The FinalABC file is not in the usual format, it may have been change since the code was written, please follow the procedure to manually copy the columns across" | ||
- | Exit Sub | ||
- | End If | ||
- | | ||
- | | ||
- | ' Determine how many rows in the input file. | ||
- | lastrow_InputFile = .Cells(Rows.Count, | ||
- | |||
- | |||
- | ' Copy all columns from BBH file into master sheet where column names match. | ||
- | For Each my_from_column In .Range(" | ||
- | For Each my_to_column In Workbooks(wb_name).Sheets(" | ||
- | If my_from_column = my_to_column Then .Range(Cells(2, | ||
- | Next my_to_column | ||
- | Next my_from_column | ||
- | | ||
- | | ||
- | ' Counts the number of cells from the input file that should have been copied across. | ||
- | count_InputFile = WorksheetFunction.CountA(.Range(" | ||
- | |||
- | End With | ||
- | | ||
- | | ||
- | ' Close the file. | ||
- | Application.DisplayAlerts = False | ||
- | .Close | ||
- | Application.DisplayAlerts = True | ||
- | | ||
- | End With | ||
- | |||
- | |||
- | ' Counts the number of cells in the FinalABC sheet that have been copied across. | ||
- | With Workbooks(wb_name) | ||
- | | ||
- | ' Activate the workbook. | ||
- | .Activate | ||
- | | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_FinalABC = .Cells(Rows.Count, | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_FinalABC < 3 Then | ||
- | lastrow_FinalABC = 3 | ||
- | End If | ||
- | | ||
- | | ||
- | ' Count how much data has been loaded into the FinalABC sheet. | ||
- | count_FinalABC = WorksheetFunction.CountA( _ | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | |||
- | | ||
- | ' Select A1. | ||
- | ScrollTo ActiveSheet.name, | ||
- | | ||
- | End With | ||
- | | ||
- | End With | ||
- | |||
- | |||
- | ' Control to ensure that the number of cells copied across matches those in the originating file. | ||
- | If count_FinalABC <> count_InputFile Then | ||
- | Message "The number of cells copied from the FinalABC file does not equal the number of cells copied to the 1042 rec. Please manually copy them across." | ||
- | Exit Sub | ||
- | End If | ||
- | |||
- | |||
- | ' Clear all objects. | ||
- | Set my_from_column = Nothing | ||
- | Set my_to_column = Nothing | ||
- | | ||
- | End Sub | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | ' Copy initial formulae down on the FinalABC sheet. | ||
- | ' Just enough data to allow the sheet to be later sorted and for the Mapping Pivots to be created. | ||
- | Sub M10110_Copy_Pre_FinalABC_Formulae_Down() | ||
- | |||
- | Dim mycell As Variant | ||
- | Dim lastrow_FinalABC As Long | ||
- | Dim Pmt_Curr As Variant | ||
- | Dim FX_Rate As Variant | ||
- | |||
- | |||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | |||
- | |||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | ' Update StatusBar. | ||
- | Application.StatusBar = "Copy pre-FinalABC formulae down..." | ||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the FinalABC sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_FinalABC = .Cells(Rows.Count, | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_FinalABC < 3 Then | ||
- | lastrow_FinalABC = 3 | ||
- | End If | ||
- | | ||
- | | ||
- | ' Ensure that FX_Rate has a default value. | ||
- | 'For Each mycell In Workbooks(my1042Rec).Sheets(" | ||
- | For Each mycell In .Range(" | ||
- | If Not mycell Like " | ||
- | Next mycell | ||
- | | ||
- | | ||
- | ' Copy using autofill. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Copy using a resize. | ||
- | ' Destination is lastrow -1 as need to exclude header row. | ||
- | 'Dim rngSource As Range | ||
- | 'Dim rngTarget As Range | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Ensure that Payment Currency is set to something. | ||
- | For Each Pmt_Curr In .Range(" | ||
- | If RTrim(LTrim(Pmt_Curr)) = "" | ||
- | Next Pmt_Curr | ||
- | | ||
- | | ||
- | ' Ensure that the FX Rate is set to a valid number. | ||
- | For Each FX_Rate In .Range(" | ||
- | If IsNumeric(FX_Rate) = False Then FX_Rate.Value = 1 | ||
- | Next FX_Rate | ||
- | | ||
- | | ||
- | ' Calculations. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Now copy and paste formula ranges as values to speed up the file processing. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Select A1. | ||
- | ScrollTo ActiveSheet.name, | ||
- | | ||
- | End With | ||
- | End With | ||
- | |||
- | | ||
- | ' Clear all objects. | ||
- | Set mycell = Nothing | ||
- | Set Pmt_Curr = Nothing | ||
- | Set FX_Rate = Nothing | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | |||
- | ' Sort FinalABC on column A in ascending order. | ||
- | Sub M10120_Sort_FinalABC_column_A() | ||
- | |||
- | Dim lastrow_FinalABC As Long | ||
- | |||
- | |||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | |||
- | |||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | |||
- | | ||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_FinalABC = .Cells(Rows.Count, | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_FinalABC < 3 Then | ||
- | lastrow_FinalABC = 3 | ||
- | End If | ||
- | |||
- | |||
- | On Error GoTo Whoa | ||
- | |||
- | |||
- | ' Do the sort. | ||
- | With .Sort | ||
- | .SortFields.Clear | ||
- | ' | ||
- | ' | ||
- | .SortFields.Add Key: | ||
- | .SetRange Range(" | ||
- | .Header = xlYes | ||
- | .MatchCase = False | ||
- | .Orientation = xlTopToBottom | ||
- | .SortMethod = xlPinYin | ||
- | .Apply | ||
- | End With | ||
- | | ||
- | End With | ||
- | | ||
- | End With | ||
- | | ||
- | Exit Sub | ||
- | |||
- | Whoa: | ||
- | MsgBox "Error " & Err.Number & " " & Err.Description, | ||
- | |||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | |||
- | ' Refresh the Mapping Pivots. | ||
- | ' These only depend on data on the FinalABC sheet. | ||
- | Sub M10200_Refresh_Mapping_Pivots() | ||
- | |||
- | Dim pt As PivotTable | ||
- | Dim pc As PivotCache | ||
- | Dim lastrow_FinalABC As Long | ||
- | Dim FinalABC_range As Range | ||
- | | ||
- | |||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | |||
- | |||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | | ||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_FinalABC = .Sheets(" | ||
- | Set FinalABC_range = Range(" | ||
- | | ||
- | | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Refresh all the pivot tables on the Mapping Pivots sheet. | ||
- | For Each pt In ActiveWorkbook.ActiveSheet.PivotTables | ||
- | | ||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | | ||
- | Set pc = ActiveWorkbook.PivotCaches.Create(xlDatabase, | ||
- | pt.ChangePivotCache pc | ||
- | pt.RefreshTable | ||
- | pt.Update | ||
- | Next | ||
- | | ||
- | | ||
- | ' Select A1. | ||
- | ScrollTo ActiveSheet.name, | ||
- | | ||
- | End With | ||
- | | ||
- | End With | ||
- | |||
- | | ||
- | ' Clear all objects. | ||
- | Set pt = Nothing | ||
- | Set pc = Nothing | ||
- | Set FinalABC_range = Nothing | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Import data into the SHEETNAME1 sheet from the " | ||
- | ' The " | ||
- | Sub M10300_Import_SHEETNAME1_from_Auto() | ||
- | |||
- | Dim SHEETNAME1 As String | ||
- | Dim count_SHEETNAME1_Auto As Double | ||
- | Dim count_SHEETNAME1 As Double | ||
- | Dim lastrow_SHEETNAME1 As Long | ||
- | Dim lastrow_SHEETNAME1_Auto As Long | ||
- | Dim i As Long | ||
- | Dim txt As String | ||
- | | ||
- | | ||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | | ||
- | | ||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | | ||
- | | ||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | | ||
- | | ||
- | With Workbooks(wb_name) | ||
- | | ||
- | ' Clear the existing SHEETNAME1 sheet. | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the SHEETNAME1 sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_SHEETNAME1 = .Cells(Rows.Count, | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_SHEETNAME1 < 3 Then | ||
- | lastrow_SHEETNAME1 = 3 | ||
- | End If | ||
- | | ||
- | | ||
- | ' Clear entire sheet, except for row 2 which contains formulae. | ||
- | With .Range(" | ||
- | .ClearContents | ||
- | End With | ||
- | | ||
- | | ||
- | ' Clear fields loaded from SHEETNAME1 file. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Clear any double lines. | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Control to confirm there is currently no data in the blue columns in the SHEETNAME1 sheet. | ||
- | If WorksheetFunction.CountA( _ | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | MsgBox "There is data still present in the blue columns in the SHEETNAME1 sheet, these should be blank. Ensure they are empty before running this process" | ||
- | Application.Calculation = xlCalculationAutomatic | ||
- | Application.EnableEvents = True | ||
- | Application.ScreenUpdating = True | ||
- | Exit Sub | ||
- | End If | ||
- | | ||
- | End With | ||
- | | ||
- | | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' | ||
- | ScrollTo ActiveSheet.name, | ||
- | | ||
- | | ||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | | ||
- | | ||
- | ' Refresh the queries. | ||
- | Selection.ListObject.QueryTable.Refresh BackgroundQuery: | ||
- | | ||
- | | ||
- | ' Control to check that the SHEETNAME1 file is in the usual format. | ||
- | If .Range(" | ||
- | Else | ||
- | MsgBox "The ' | ||
- | Exit Sub | ||
- | End If | ||
- | | ||
- | | ||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | | ||
- | | ||
- | ' Copy data from " | ||
- | lastrow_SHEETNAME1_Auto = .Cells(Rows.Count, | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Counts the number of cells in the SHEETNAME1 file that should have been copied across. | ||
- | count_SHEETNAME1_Auto = WorksheetFunction.CountA( _ | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | End With | ||
- | |||
- | |||
- | ' Tidy up some columns in the SHEETNAME1 sheet. | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_SHEETNAME1 = .Cells(Rows.Count, | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_SHEETNAME1 < 3 Then | ||
- | lastrow_SHEETNAME1 = 3 | ||
- | End If | ||
- | | ||
- | | ||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | | ||
- | | ||
- | 'Set the SEDOL range format to text. | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Adds 0's to the front of the sedol number. | ||
- | Dim x | ||
- | For i = 2 To lastrow_SHEETNAME1 | ||
- | txt = .Range(" | ||
- | If Len(txt) < 7 Then | ||
- | For x = 1 To (7 - Len(txt)) | ||
- | txt = " | ||
- | Next x | ||
- | End If | ||
- | | ||
- | If IsNumeric(txt) Then | ||
- | txt = "'" | ||
- | End If | ||
- | | ||
- | .Range(" | ||
- | Next i | ||
- | | ||
- | | ||
- | ' In the SHEETNAME1 file, the sedol name is spread out over two columsn, so we can't do a straight copy and paste | ||
- | ' therefore we must put a formula in the SHEETNAME1 sheet to concatenate the two columns. | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | | ||
- | | ||
- | ' Convert the pay date using a formula. | ||
- | ' In order to convert the pay date it is neccessary to use a formula that copies the data from the SHEETNAME1 file instead of copy/ | ||
- | .Range(" | ||
- | |||
- | | ||
- | ' Change format of date. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Change formulae to values. | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Counts the number of cells in the SHEETNAME1 that have been copied across. | ||
- | count_SHEETNAME1 = WorksheetFunction.CountA( _ | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Control to ensure that the number of cells copied across matches those in the originating file. | ||
- | If count_SHEETNAME1 <> count_SHEETNAME1_Auto Then | ||
- | MsgBox "The number of cells copied from the SHEETNAME1 file does not equal the number of cells copied to the 1042 rec. Please manually copy them across." | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | |||
- | Exit Sub | ||
- | End If | ||
- | | ||
- | | ||
- | ' Select A1. | ||
- | ScrollTo ActiveSheet.name, | ||
- | | ||
- | End With | ||
- | | ||
- | | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the FinalABC sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Resets formulae on FinalABC to point to " | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | |||
- | .Range(" | ||
- | .Range(" | ||
- | End With | ||
- | |||
- | End With | ||
- | | ||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Import data into the SHEETNAME1 sheet from a file. | ||
- | ' Filename must be in the format SHEETNAME1CCYYMMDD.csv. | ||
- | ' If not MMDD available then use 9999 in their place. | ||
- | Sub M10300_Import_SHEETNAME1() | ||
- | |||
- | Dim fileToOpen As Variant | ||
- | Dim count_SHEETNAME1 As Double | ||
- | Dim count_InputFile As Double | ||
- | Dim fileToOpen_name As String | ||
- | Dim FileParts() As String | ||
- | Dim lastrow_SHEETNAME1 As Long | ||
- | Dim lastrow_FinalABC As Long | ||
- | Dim lastrow_InputFile As Long | ||
- | Dim Include_Exclude As Variant | ||
- | Dim i As Long | ||
- | Dim txt As String | ||
- | |||
- | |||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | |||
- | |||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | ' Clear the SHEETNAME1 sheet. | ||
- | Call M10010_Clear_SHEETNAME1 | ||
- | |||
- | |||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | |||
- | |||
- | ' Prompt for a file. | ||
- | fileToOpen = Application.GetOpenFilename(" | ||
- | If fileToOpen = False Then | ||
- | MsgBox "No BBH file selected. | ||
- | Exit Sub | ||
- | End If | ||
- | | ||
- | FileParts() = Split(fileToOpen, | ||
- | fileToOpen_name = FileParts(UBound(FileParts)) | ||
- | |||
- | |||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | |||
- | | ||
- | ' Start of copying columns across. | ||
- | With Workbooks.Open(fileToOpen) | ||
- | |||
- | With .Sheets(1) | ||
- | |||
- | ' Control to check that the SHEETNAME1 file is in the usual format. | ||
- | If .Range(" | ||
- | Else | ||
- | MsgBox "The SHEETNAME1 file is not in the usual format, it may have been change since the code was written, please follow the procedure to manually copy the columns across." | ||
- | If ctrl_close_erroneous_files = True Then | ||
- | Application.DisplayAlerts = False | ||
- | Workbooks(fileToOpen_name).Close | ||
- | Application.DisplayAlerts = True | ||
- | End If | ||
- | Exit Sub | ||
- | End If | ||
- | | ||
- | | ||
- | ' Determine how many rows in the input file. | ||
- | lastrow_InputFile = .Cells(Rows.Count, | ||
- | | ||
- | End With | ||
- | | ||
- | | ||
- | ' Copy data to the SHEETNAME1 sheet. | ||
- | With .Sheets(1) | ||
- | | ||
- | ' Copy data from the Input file to the SHEETNAME1 sheet. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' In the SHEETNAME1 file, the sedol name is spread out over two columsn, so we can't do a straight copy and paste | ||
- | ' therefore we must put a formula in the SHEETNAME1 sheet to concatenate the two columns. | ||
- | Workbooks(wb_name).Sheets(" | ||
- | | ||
- | | ||
- | ' In order to convert the pay date it is neccessary to use a formula that copies the data from the SHEETNAME1 file instead of copy/ | ||
- | Workbooks(wb_name).Sheets(" | ||
- | | ||
- | | ||
- | ' Copy data from the Input file to the SHEETNAME1 sheet. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Counts the number of cells in the SHEETNAME1 file that should have been copied across. | ||
- | count_InputFile = WorksheetFunction.CountA( _ | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | |||
- | End With | ||
- | | ||
- | End With | ||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the SHEETNAME1 sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_SHEETNAME1 = .Cells(Rows.Count, | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_SHEETNAME1 < 3 Then | ||
- | lastrow_SHEETNAME1 = 3 | ||
- | End If | ||
- | |||
- | |||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | |||
- | |||
- | 'Set the SEDOL range format to text. | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Adds 0's to the front of the sedol number. | ||
- | Dim x | ||
- | For i = 2 To lastrow_SHEETNAME1 | ||
- | txt = .Range(" | ||
- | If Len(txt) < 7 Then | ||
- | For x = 1 To (7 - Len(txt)) | ||
- | txt = " | ||
- | Next x | ||
- | End If | ||
- | | ||
- | If IsNumeric(txt) Then | ||
- | txt = "'" | ||
- | End If | ||
- | | ||
- | .Range(" | ||
- | Next i | ||
- | |||
- | |||
- | ' Copy and paste SEDOL as values to allow vlookups to work correctly. | ||
- | ' Certain SEDOLs are only numbers and numbers don't work in vlookups to strings. | ||
- | .Range(" | ||
- | | ||
- | |||
- | ' In the SHEETNAME1 file, the sedol name is spread out over two columsn, so we can't do a straight copy and paste | ||
- | ' therefore we must put a formula in the SHEETNAME1 sheet to concatenate the two columns. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | | ||
- | | ||
- | ' In order to convert the pay date it is neccessary to use a formula that copies the data from the SHEETNAME1 file instead of copy/ | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Copy " | ||
- | For Each Include_Exclude In .Range(" | ||
- | If RTrim(LTrim(Include_Exclude)) = "" | ||
- | Next Include_Exclude | ||
- | | ||
- | | ||
- | ' Counts the number of cells in the SHEETNAME1 sheet that have been copied across. | ||
- | count_SHEETNAME1 = WorksheetFunction.CountA( _ | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Select A1. | ||
- | ScrollTo ActiveSheet.name, | ||
- | | ||
- | End With | ||
- | | ||
- | | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the FinalABC sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_FinalABC = .Cells(Rows.Count, | ||
- | | ||
- | | ||
- | ' Resets formulae on FinalABC to point to " | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | ' | ||
- | .Range(" | ||
- | ' | ||
- | .Range(" | ||
- | | ||
- | End With | ||
- | | ||
- | End With | ||
- | |||
- | |||
- | ' Control to ensure that the number of cells copied across matches those in the originating file. | ||
- | If count_SHEETNAME1 <> count_InputFile Then | ||
- | MsgBox "The number of cells copied from the Input File does not equal the number of cells copied to the SHEETNAME1 sheet. Please manually copy them across." | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | |||
- | | ||
- | ' Close the SHEETNAME1 file. | ||
- | If ctrl_close_erroneous_files = True Then | ||
- | Application.DisplayAlerts = False | ||
- | Workbooks(fileToOpen_name).Close | ||
- | Application.DisplayAlerts = True | ||
- | End If | ||
- | Exit Sub | ||
- | End If | ||
- | |||
- | | ||
- | ' Close the SHEETNAME1 file. | ||
- | Application.DisplayAlerts = False | ||
- | Workbooks(fileToOpen_name).Close | ||
- | Application.DisplayAlerts = True | ||
- | |||
- | |||
- | ' Clear all objects. | ||
- | Set Include_Exclude = Nothing | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Updates the formulae on the FinalABC sheet to only reference the specific number of rows actually loaded into the | ||
- | ' FinalABC sheet instead of something like A:A which would reference over 1 million rows and therefore may slow down | ||
- | ' calculations etc. | ||
- | Sub M10400_Update_FinalABC_Formulae() | ||
- | |||
- | Dim lastrow_SHEETNAME1 As Long | ||
- | Dim lastrow_FinalABC As Long | ||
- | |||
- | | ||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | | ||
- | | ||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | | ||
- | |||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_SHEETNAME1 = Sheets(" | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_SHEETNAME1 < 3 Then | ||
- | lastrow_SHEETNAME1 = 3 | ||
- | End If | ||
- | |||
- | |||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_FinalABC = .Cells(Rows.Count, | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_FinalABC < 3 Then | ||
- | lastrow_FinalABC = 3 | ||
- | End If | ||
- | |||
- | |||
- | ' Resets formulae on FinalABC. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | End With | ||
- | End With | ||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Copy the updated formula on the FinalABC sheet down for all populated rows. | ||
- | Sub M10410_Copy_Post_FinalABC_Formulae_Down() | ||
- | |||
- | Dim mycell As Variant | ||
- | Dim lastrow_FinalABC As Long | ||
- | |||
- | |||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | | ||
- | | ||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | ' Update StatusBar. | ||
- | Application.StatusBar = "Copy post-FinalABC Formulae down..." | ||
- | |||
- | | ||
- | With Workbooks(wb_name) | ||
- | | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | |||
- | |||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_FinalABC = .Cells(Rows.Count, | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_FinalABC < 3 Then | ||
- | lastrow_FinalABC = 3 | ||
- | End If | ||
- | |||
- | | ||
- | ' For Each mycell In Workbooks(my1042Rec).Sheets(" | ||
- | For Each mycell In .Range(" | ||
- | If Not mycell Like " | ||
- | Next mycell | ||
- | |||
- | |||
- | ' Copies formulae down. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | |||
- | |||
- | ' Calculations. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | 'TODO below calc is not needed now. Only needed once SHEETNAME1 file is loaded, as AG to AK use SHEETNAME1 data. | ||
- | .Range(" | ||
- | .Range(" | ||
- | |||
- | |||
- | ' Now copy and paste formula ranges as values to speed up the file processing. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | End With | ||
- | End With | ||
- | |||
- | |||
- | ' Clear all objects. | ||
- | Set mycell = Nothing | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | ' Copy the updated formula on the FinalABC sheet down for all populated rows. | ||
- | ' Speeds this up using Arrays | ||
- | Sub M10415_Copy_Post_FinalABC_Formulae_Down_Array() | ||
- | |||
- | Dim mycell As Variant | ||
- | Dim lastrow_SHEETNAME1 As Long | ||
- | Dim lastrow_FinalABC As Long | ||
- | |||
- | Dim working As Variant | ||
- | Dim column_a_FinalABC As Variant | ||
- | Dim column_d_FinalABC As Variant | ||
- | Dim column_k_FinalABC As Variant | ||
- | Dim column_l_FinalABC As Variant | ||
- | Dim column_n_FinalABC As Variant | ||
- | Dim column_o_FinalABC As Variant | ||
- | Dim column_p_FinalABC As Variant | ||
- | Dim column_r_FinalABC As Variant | ||
- | Dim column_s_FinalABC As Variant | ||
- | Dim column_ae_FinalABC As Variant | ||
- | Dim column_ak_FinalABC As Variant | ||
- | Dim column_al_FinalABC As Variant | ||
- | | ||
- | Dim column_a_SHEETNAME1 As Variant | ||
- | Dim column_f_SHEETNAME1 As Variant | ||
- | Dim column_g_SHEETNAME1 As Variant | ||
- | Dim column_i_SHEETNAME1 As Variant | ||
- | Dim column_j_SHEETNAME1 As Variant | ||
- | Dim column_ao_SHEETNAME1 As Variant | ||
- | | ||
- | Dim n As Long | ||
- | |||
- | |||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | | ||
- | | ||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | ' Update StatusBar. | ||
- | Application.StatusBar = "Copy post-FinalABC Formulae down..." | ||
- | |||
- | | ||
- | With Workbooks(wb_name) | ||
- | | ||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_SHEETNAME1 = Sheets(" | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_SHEETNAME1 < 3 Then | ||
- | lastrow_SHEETNAME1 = 3 | ||
- | End If | ||
- | | ||
- | | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | |||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_FinalABC = .Cells(Rows.Count, | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_FinalABC < 3 Then | ||
- | lastrow_FinalABC = 3 | ||
- | End If | ||
- | |||
- | ReDim working(1 To lastrow_FinalABC, | ||
- | working = Range(" | ||
- | | ||
- | ReDim column_a_FinalABC(1 To lastrow_FinalABC, | ||
- | ReDim column_k_FinalABC(1 To lastrow_FinalABC, | ||
- | ReDim column_l_FinalABC(1 To lastrow_FinalABC, | ||
- | ReDim column_n_FinalABC(1 To lastrow_FinalABC, | ||
- | ReDim column_o_FinalABC(1 To lastrow_FinalABC, | ||
- | ReDim column_p_FinalABC(1 To lastrow_FinalABC, | ||
- | ReDim column_r_FinalABC(1 To lastrow_FinalABC, | ||
- | ReDim column_s_FinalABC(1 To lastrow_FinalABC, | ||
- | ReDim column_ae_FinalABC(1 To lastrow_FinalABC, | ||
- | ReDim column_ak_FinalABC(1 To lastrow_FinalABC, | ||
- | ReDim column_al_FinalABC(1 To lastrow_FinalABC, | ||
- | | ||
- | ReDim column_a_SHEETNAME1(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_f_SHEETNAME1(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_g_SHEETNAME1(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_i_SHEETNAME1(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_j_SHEETNAME1(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_ao_SHEETNAME1(1 To lastrow_SHEETNAME1, | ||
- | | ||
- | | ||
- | ' Column AE | ||
- | ' FX_Rate | ||
- | working = Range(" | ||
- | column_ae_FinalABC = Range(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | If Not column_ae_FinalABC(n, | ||
- | working(n, 1) = 1 | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | ' Column P - needed before column N | ||
- | ' =IF(R2="", | ||
- | column_r_FinalABC = Range(" | ||
- | column_k_FinalABC = Range(" | ||
- | column_s_FinalABC = Range(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | If column_r_FinalABC(n, | ||
- | working(n, 1) = column_k_FinalABC(n, | ||
- | Else | ||
- | working(n, 1) = column_k_FinalABC(n, | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Column N - needed before column M | ||
- | ' =P2*AE2 | ||
- | column_p_FinalABC = Range(" | ||
- | column_ae_FinalABC = Range(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | working(n, 1) = column_p_FinalABC(n, | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Column M | ||
- | ' | ||
- | column_l_FinalABC = Range(" | ||
- | column_n_FinalABC = Range(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | working(n, 1) = column_l_FinalABC(n, | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | | ||
- | ' Column Q | ||
- | ' =IF(R2="", | ||
- | column_r_FinalABC = Range(" | ||
- | column_s_FinalABC = Range(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | If column_r_FinalABC(n, | ||
- | working(n, 1) = column_s_FinalABC(n, | ||
- | Else | ||
- | working(n, 1) = column_r_FinalABC(n, | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | | ||
- | ' Column AI | ||
- | ' =IF(ISNA(VLOOKUP(D2, | ||
- | column_d_FinalABC = Range(" | ||
- | column_g_SHEETNAME1 = Range(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | working(n, 1) = ArrayFindEx(column_g_SHEETNAME1, | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | | ||
- | ' Column AJ | ||
- | 'D2=D1 | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Column AK | ||
- | ' =IF(COUNTIF($A$1: | ||
- | column_a_FinalABC = Range(" | ||
- | column_l_FinalABC = Range(" | ||
- | column_a_SHEETNAME1 = Sheets(" | ||
- | column_f_SHEETNAME1 = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If ArrayCountIf(column_a_FinalABC, | ||
- | working(n, 1) = " | ||
- | Else | ||
- | working(n, 1) = ArraySumIf(column_a_FinalABC, | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Column AL | ||
- | ' =IF(A2=A1, | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | | ||
- | ' Column AM | ||
- | ' =IF(COUNTIF($A$1: | ||
- | column_a_FinalABC = Range(" | ||
- | column_k_FinalABC = Range(" | ||
- | column_a_SHEETNAME1 = Sheets(" | ||
- | column_ao_SHEETNAME1 = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If ArrayCountIf(column_a_FinalABC, | ||
- | working(n, 1) = " | ||
- | Else | ||
- | working(n, 1) = ArraySumIf(column_a_FinalABC, | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | | ||
- | ' Column AR | ||
- | ' =IF(COUNTIF($A$1: | ||
- | column_a_FinalABC = Range(" | ||
- | column_p_FinalABC = Range(" | ||
- | column_a_SHEETNAME1 = Sheets(" | ||
- | column_j_SHEETNAME1 = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If ArrayCountIf(column_a_FinalABC, | ||
- | working(n, 1) = " | ||
- | Else | ||
- | working(n, 1) = ArraySumIf(column_a_FinalABC, | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Column AS | ||
- | ' =IF(A2=A1, | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | | ||
- | ' Column AT | ||
- | ' =IF(COUNTIF($A$1: | ||
- | column_a_FinalABC = Range(" | ||
- | column_o_FinalABC = Range(" | ||
- | column_a_SHEETNAME1 = Sheets(" | ||
- | column_i_SHEETNAME1 = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If ArrayCountIf(column_a_FinalABC, | ||
- | working(n, 1) = " | ||
- | Else | ||
- | working(n, 1) = ArraySumIf(column_a_FinalABC, | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | End With | ||
- | End With | ||
- | |||
- | |||
- | ' Clear all objects. | ||
- | Set mycell = Nothing | ||
- | |||
- | Set working = Nothing | ||
- | | ||
- | Set column_a_FinalABC = Nothing | ||
- | Set column_d_FinalABC = Nothing | ||
- | Set column_k_FinalABC = Nothing | ||
- | Set column_l_FinalABC = Nothing | ||
- | Set column_n_FinalABC = Nothing | ||
- | Set column_o_FinalABC = Nothing | ||
- | Set column_p_FinalABC = Nothing | ||
- | Set column_r_FinalABC = Nothing | ||
- | Set column_s_FinalABC = Nothing | ||
- | Set column_ae_FinalABC = Nothing | ||
- | Set column_ak_FinalABC = Nothing | ||
- | Set column_al_FinalABC = Nothing | ||
- | |||
- | Set column_a_SHEETNAME1 = Nothing | ||
- | Set column_f_SHEETNAME1 = Nothing | ||
- | Set column_i_SHEETNAME1 = Nothing | ||
- | Set column_j_SHEETNAME1 = Nothing | ||
- | Set column_ao_SHEETNAME1 = Nothing | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | ' Copy pre SHEETNAME1 formula down. | ||
- | ' Just enough data to allow SHEETNAME1 sheet to be sorted. | ||
- | Sub M10500_Copy_Pre_SHEETNAME1_Formulae_Down() | ||
- | |||
- | Dim lastrow_SHEETNAME1 As Long | ||
- | |||
- | |||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | | ||
- | | ||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | ' Update StatusBar. | ||
- | Application.StatusBar = "Copy pre-SHEETNAME1 Formulae down..." | ||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | |||
- | |||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_SHEETNAME1 = .Cells(Rows.Count, | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_SHEETNAME1 < 3 Then | ||
- | lastrow_SHEETNAME1 = 3 | ||
- | End If | ||
- | |||
- | |||
- | ' Copies formulae down. | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Calculations. | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Now copy and paste formula ranges as values to speed up the file processing. | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Select A1. | ||
- | ScrollTo ActiveSheet.name, | ||
- | End With | ||
- | End With | ||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Copy pre SHEETNAME1 formula down using Arrays for speed. | ||
- | ' Just enough data to allow SHEETNAME1 sheet to be sorted. | ||
- | Sub M10505_Copy_Pre_SHEETNAME1_Formulae_Down_array() | ||
- | |||
- | Dim lastrow_SHEETNAME1 As Long | ||
- | Dim lastrow_SECT As Long | ||
- | | ||
- | Dim working As Variant | ||
- | Dim column_a As Variant | ||
- | Dim column_b As Variant | ||
- | Dim column_c As Variant | ||
- | Dim column_n As Variant | ||
- | Dim column_a_SECT As Variant | ||
- | Dim column_b_SECT As Variant | ||
- | | ||
- | Dim n As Long | ||
- | |||
- | |||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | | ||
- | | ||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | | ||
- | ' Update StatusBar. | ||
- | Application.StatusBar = "Copy pre-SHEETNAME1 Formulae down..." | ||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | |||
- | |||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_SHEETNAME1 = .Cells(Rows.Count, | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_SHEETNAME1 < 3 Then | ||
- | lastrow_SHEETNAME1 = 3 | ||
- | End If | ||
- | |||
- | lastrow_SECT = Sheets(" | ||
- | | ||
- | | ||
- | ReDim working(1 To lastrow_SHEETNAME1, | ||
- | working = Range(" | ||
- | | ||
- | ReDim column_a(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_b(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_c(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_n(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_a_SECT(1 To lastrow_SECT, | ||
- | ReDim column_b_SECT(1 To lastrow_SECT, | ||
- | |||
- | |||
- | ' Column B | ||
- | ' | ||
- | column_n = Range(" | ||
- | column_a_SECT = Sheets(" | ||
- | column_b_SECT = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | working(n, 1) = ArrayFind(column_a_SECT, | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Column A | ||
- | ' | ||
- | column_b = Range(" | ||
- | column_c = Range(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | working(n, 1) = column_b(n, 1) & " - " & WorksheetFunction.Text(column_c(n, | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | |||
- | | ||
- | ' Select A1. | ||
- | ScrollTo ActiveSheet.name, | ||
- | End With | ||
- | End With | ||
- | |||
- | | ||
- | ' Clear all objects. | ||
- | Set working = Nothing | ||
- | | ||
- | Set column_a = Nothing | ||
- | Set column_b = Nothing | ||
- | Set column_c = Nothing | ||
- | Set column_n = Nothing | ||
- | Set column_a_SECT = Nothing | ||
- | Set column_b_SECT = Nothing | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Sorts the SHEETNAME1 sheet by Columns A and M in ascending order. | ||
- | Sub M10510_Sort_SHEETNAME1_column_A() | ||
- | |||
- | Dim lastrow_SHEETNAME1 As Long | ||
- | |||
- | |||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | | ||
- | | ||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | ' Update StatusBar. | ||
- | Application.StatusBar = "Sort SHEETNAME1...Column A and M" | ||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | | ||
- | With .Sheets(" | ||
- | | ||
- | ' Active the sheet. | ||
- | .Activate | ||
- | |||
- | |||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_SHEETNAME1 = .Cells(Rows.Count, | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_SHEETNAME1 < 3 Then | ||
- | lastrow_SHEETNAME1 = 3 | ||
- | End If | ||
- | |||
- | | ||
- | ' Checks if all ISINs are populated. | ||
- | If WorksheetFunction.CountA(.Columns(" | ||
- | 'If MsgBox(" | ||
- | If MsgBox(" | ||
- | Exit Sub | ||
- | End If | ||
- | End If | ||
- | |||
- | | ||
- | ' Do the sort. | ||
- | With .Sort | ||
- | | ||
- | ' | ||
- | With .SortFields | ||
- | .Clear | ||
- | .Add Key: | ||
- | .Add Key: | ||
- | End With | ||
- | | ||
- | .SetRange Range(" | ||
- | .Header = xlYes | ||
- | .MatchCase = False | ||
- | .Orientation = xlTopToBottom | ||
- | .SortMethod = xlPinYin | ||
- | .Apply | ||
- | | ||
- | End With | ||
- | |||
- | |||
- | ' Select A1. | ||
- | ScrollTo ActiveSheet.name, | ||
- | | ||
- | End With | ||
- | End With | ||
- | End Sub | ||
- | |||
- | |||
- | |||
- | |||
- | ' Updates the formulae on the SHEETNAME1 sheet to only reference the specific number of rows actually loaded into the SHEETNAME1 sheet | ||
- | ' instead of something like A:A which would reference over 1 million rows and therefore may slow down calculations etc. | ||
- | Sub M10520_Update_SHEETNAME1_Formulae() | ||
- | |||
- | Dim lastrow_SHEETNAME1 As Long | ||
- | Dim lastrow_SECT As Long | ||
- | Dim lastrow_References As Long | ||
- | Dim lastrow_References_adjusted_rate As Long | ||
- | Dim lastrow_References_g3_location As Long | ||
- | Dim lastrow_References_excemption_code As Long | ||
- | Dim lastrow_References_allowed_locations As Long | ||
- | Dim lastrow_FinalABC As Long | ||
- | Dim lastrow_MappingPivots As Long | ||
- | Dim lastrow_MappingPivots2 As Long | ||
- | Dim lastrow_MappingPivots3 As Long | ||
- | Dim lastrow_Wxxxx As Long | ||
- | Dim lastrow_HOLDINGS As Long | ||
- | Dim lastrow_TRANSACTIONS As Long | ||
- | Dim lastrow_CUST As Long | ||
- | Dim lastrow_QSHEET As Long | ||
- | |||
- | | ||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | | ||
- | | ||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | | ||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_SHEETNAME1 = .Sheets(" | ||
- | lastrow_SECT = .Sheets(" | ||
- | lastrow_References = .Sheets(" | ||
- | lastrow_References_adjusted_rate = .Sheets(" | ||
- | lastrow_References_g3_location = .Sheets(" | ||
- | lastrow_References_excemption_code = .Sheets(" | ||
- | lastrow_References_allowed_locations = .Sheets(" | ||
- | lastrow_FinalABC = .Sheets(" | ||
- | lastrow_HOLDINGS = .Sheets(" | ||
- | lastrow_MappingPivots = .Sheets(" | ||
- | lastrow_MappingPivots2 = .Sheets(" | ||
- | lastrow_MappingPivots3 = .Sheets(" | ||
- | lastrow_Wxxxx = .Sheets(" | ||
- | lastrow_TRANSACTIONS = .Sheets(" | ||
- | lastrow_CUST = .Sheets(" | ||
- | lastrow_QSHEET = .Sheets(" | ||
- | |||
- | |||
- | ' Updates formulae on SHEETNAME1. | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | End With | ||
- | | ||
- | End With | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Returns the number of vCrit found within the array oArrWithCrit. | ||
- | Function ArrayCountIfSequential(oArrWithCrit As Variant, vCrit As Variant) | ||
- | Dim lRow As Long | ||
- | | ||
- | For lRow = LBound(oArrWithCrit, | ||
- | If oArrWithCrit(lRow, | ||
- | ArrayCountIfSequential = ArrayCountIf + 1 | ||
- | End If | ||
- | Next | ||
- | End Function | ||
- | |||
- | |||
- | ' Binary Search of array. | ||
- | ' Returns the number of vCrit found within the array oArrWithCrit. | ||
- | Function ArrayCountIf(oArrWithCrit As Variant, vCrit As Variant) | ||
- | Dim low As Long | ||
- | low = LBound(oArrWithCrit) | ||
- | Dim high As Long | ||
- | high = UBound(oArrWithCrit) | ||
- | Dim i As Long | ||
- | Dim J As Long | ||
- | Dim result As Boolean | ||
- | | ||
- | ArrayCountIf = 0 | ||
- | | ||
- | Do While low <= high | ||
- | i = (low + high) / 2 | ||
- | If vCrit = oArrWithCrit(i, | ||
- | ArrayCountIf = ArrayCountIf + 1 | ||
- | ' Now that found run sequentially while same value | ||
- | J = i - 1 | ||
- | i = i + 1 | ||
- | | ||
- | Do While (i <= high) | ||
- | If vCrit = oArrWithCrit(i, | ||
- | ArrayCountIf = ArrayCountIf + 1 | ||
- | i = i + 1 | ||
- | Else | ||
- | Exit Do | ||
- | End If | ||
- | Loop | ||
- | | ||
- | Do While (J >= low) | ||
- | If vCrit = oArrWithCrit(J, | ||
- | ArrayCountIf = ArrayCountIf + 1 | ||
- | J = J - 1 | ||
- | Else | ||
- | Exit Do | ||
- | End If | ||
- | Loop | ||
- | | ||
- | Exit Do | ||
- | ElseIf vCrit < oArrWithCrit(i, | ||
- | high = (i - 1) | ||
- | Else | ||
- | low = (i + 1) | ||
- | End If | ||
- | Loop | ||
- | | ||
- | End Function | ||
- | |||
- | |||
- | ' Returns the sum of all oArrWithValues for all vCrit found within the array oArrWithCrit. | ||
- | Function ArraySumIfSequential(oArrWithCrit As Variant, vCrit As Variant, oArrWithValues As Variant) | ||
- | Dim vArr1 As Variant | ||
- | Dim vArr2 As Variant | ||
- | Dim lRow As Long | ||
- | If (UBound(oArrWithCrit) - LBound(oArrWithCrit)) = (UBound(oArrWithValues) - LBound(oArrWithValues)) Then | ||
- | For lRow = LBound(oArrWithCrit, | ||
- | If oArrWithCrit(lRow, | ||
- | ArraySumIfSequential = ArraySumIfSequential + oArrWithValues(lRow, | ||
- | End If | ||
- | Next | ||
- | Else | ||
- | ArraySumIfSequential = " | ||
- | End If | ||
- | |||
- | |||
- | ' Clear all objects. | ||
- | Set vArr1 = Nothing | ||
- | Set vArr2 = Nothing | ||
- | |||
- | End Function | ||
- | |||
- | |||
- | ' Returns the sum of all oArrWithValues for all vCrit found within the array oArrWithCrit. | ||
- | Function ArraySumIf(oArrWithCrit As Variant, vCrit As Variant, oArrWithValues As Variant) | ||
- | Dim low As Long | ||
- | low = LBound(oArrWithCrit) | ||
- | Dim high As Long | ||
- | high = UBound(oArrWithCrit) | ||
- | Dim i As Long | ||
- | Dim J As Long | ||
- | Dim result As Boolean | ||
- | | ||
- | ArraySumIf = 0 | ||
- | | ||
- | Do While low <= high | ||
- | i = (low + high) / 2 | ||
- | If vCrit = oArrWithCrit(i, | ||
- | If IsNumeric(oArrWithValues(i, | ||
- | ArraySumIf = ArraySumIf + oArrWithValues(i, | ||
- | End If | ||
- | | ||
- | ' Now that found run sequentially while same value | ||
- | i = i + 1 | ||
- | J = J - 1 | ||
- | | ||
- | Do While (i <= high) | ||
- | If vCrit = oArrWithCrit(i, | ||
- | If IsNumeric(oArrWithValues(i, | ||
- | ArraySumIf = ArraySumIf + oArrWithValues(i, | ||
- | End If | ||
- | i = i + 1 | ||
- | Else | ||
- | Exit Do | ||
- | End If | ||
- | Loop | ||
- | | ||
- | Do While (J >= low) | ||
- | If vCrit = oArrWithCrit(J, | ||
- | If IsNumeric(oArrWithValues(i, | ||
- | ArraySumIf = ArraySumIf + oArrWithValues(i, | ||
- | End If | ||
- | J = J - 1 | ||
- | Else | ||
- | Exit Do | ||
- | End If | ||
- | Loop | ||
- | | ||
- | Exit Do | ||
- | ElseIf vCrit < oArrWithCrit(i, | ||
- | high = (i - 1) | ||
- | Else | ||
- | low = (i + 1) | ||
- | End If | ||
- | Loop | ||
- | | ||
- | End Function | ||
- | |||
- | |||
- | |||
- | ' Returns the sum of all oArrWithValues for all vCrit found within the array oArrWithCrit. | ||
- | Function ArraySumIfx(oArrWithCrit As Variant, vCrit As Variant, oArrWithValues As Variant) | ||
- | Dim low As Long | ||
- | low = LBound(oArrWithCrit) | ||
- | Dim high As Long | ||
- | high = UBound(oArrWithCrit) | ||
- | Dim i As Long | ||
- | Dim J As Long | ||
- | Dim result As Boolean | ||
- | | ||
- | ArraySumIf = 0 | ||
- | | ||
- | Do While low <= high | ||
- | i = (low + high) / 2 | ||
- | If vCrit = oArrWithCrit(i, | ||
- | ArraySumIf = ArraySumIf + oArrWithValues(i, | ||
- | ' Now that found run sequentially while same value | ||
- | i = i + 1 | ||
- | J = J - 1 | ||
- | | ||
- | Do While (i <= high) | ||
- | If vCrit = oArrWithCrit(i, | ||
- | ArraySumIf = ArraySumIf + oArrWithValues(i, | ||
- | i = i + 1 | ||
- | Else | ||
- | Exit Do | ||
- | End If | ||
- | Loop | ||
- | | ||
- | Do While (J >= low) | ||
- | If vCrit = oArrWithCrit(J, | ||
- | ArraySumIf = ArraySumIf + oArrWithValues(i, | ||
- | J = J - 1 | ||
- | Else | ||
- | Exit Do | ||
- | End If | ||
- | Loop | ||
- | | ||
- | Exit Do | ||
- | ElseIf vCrit < oArrWithCrit(i, | ||
- | high = (i - 1) | ||
- | Else | ||
- | low = (i + 1) | ||
- | End If | ||
- | Loop | ||
- | | ||
- | End Function | ||
- | |||
- | |||
- | |||
- | ' Tries to find vCrit within oArrWithCrit. | ||
- | ' If found then return corresponding oArrWithValues otherwise vDefault. | ||
- | Function ArrayFindSequential(oArrWithCrit As Variant, vCrit As Variant, oArrWithValues As Variant, vDefault As Variant) | ||
- | |||
- | Dim vArr1 As Variant | ||
- | Dim vArr2 As Variant | ||
- | Dim lRow As Long | ||
- | ArrayFindSequential = vDefault | ||
- | If (UBound(oArrWithCrit) - LBound(oArrWithCrit)) = (UBound(oArrWithValues) - LBound(oArrWithValues)) Then | ||
- | For lRow = LBound(oArrWithCrit, | ||
- | If oArrWithCrit(lRow, | ||
- | ArrayFindSequential = oArrWithValues(lRow, | ||
- | Exit Function | ||
- | End If | ||
- | Next | ||
- | Else | ||
- | ArrayFindSequential = " | ||
- | End If | ||
- | |||
- | | ||
- | ' Clear all objects. | ||
- | Set vArr1 = Nothing | ||
- | Set vArr2 = Nothing | ||
- | |||
- | End Function | ||
- | |||
- | |||
- | ' Binary Search of array. | ||
- | ' Tries to find vCrit within oArrWithCrit. | ||
- | ' If found then return corresponding oArrWithValues otherwise vDefault. | ||
- | ' Note that due to way that binary search works this may not report on the very 1st instance of that vCrit if this | ||
- | ' was done sequentially. | ||
- | ' data against the same vCrit. | ||
- | Function ArrayFind(oArrWithCrit As Variant, vCrit As Variant, oArrWithValues As Variant, vDefault As Variant) | ||
- | Dim low As Long | ||
- | low = LBound(oArrWithCrit) | ||
- | Dim high As Long | ||
- | high = UBound(oArrWithCrit) | ||
- | Dim i As Long | ||
- | Dim result As Boolean | ||
- | ArrayFind = vDefault | ||
- | | ||
- | Do While low <= high | ||
- | i = (low + high) / 2 | ||
- | If vCrit = oArrWithCrit(i, | ||
- | ArrayFind = oArrWithValues(i, | ||
- | Exit Do | ||
- | ElseIf vCrit < oArrWithCrit(i, | ||
- | high = (i - 1) | ||
- | Else | ||
- | low = (i + 1) | ||
- | End If | ||
- | Loop | ||
- | | ||
- | End Function | ||
- | |||
- | |||
- | |||
- | |||
- | ' Tries to find vCrit within oArrWithCrit. | ||
- | ' If found then returns vFoundValue otherwise vNotFoundValue. | ||
- | ' | ||
- | Function ArrayFindSequentialEx(oArrWithCrit As Variant, vCrit As Variant, vFoundValue As Variant, vNotFoundValue As Variant) | ||
- | Dim vArr1 As Variant | ||
- | Dim vArr2 As Variant | ||
- | Dim lRow As Long | ||
- | ArrayFindSequentialEx = vNotFoundValue | ||
- | For lRow = LBound(oArrWithCrit, | ||
- | If oArrWithCrit(lRow, | ||
- | ArrayFindSequentialEx = vFoundValue | ||
- | Exit Function | ||
- | End If | ||
- | Next | ||
- | |||
- | | ||
- | ' Clear all objects. | ||
- | Set vArr1 = Nothing | ||
- | Set vArr2 = Nothing | ||
- | |||
- | End Function | ||
- | |||
- | |||
- | ' Tries to find vCrit within oArrWithCrit. | ||
- | ' If found then returns vFoundValue otherwise vNotFoundValue. | ||
- | ' Note that due to way that binary search works this may not report on the very 1st instance of that vCrit if this | ||
- | ' was done sequentially. | ||
- | ' data against the same vCrit. | ||
- | Function ArrayFindEx(oArrWithCrit As Variant, vCrit As Variant, vFoundValue As Variant, vNotFoundValue As Variant) | ||
- | Dim low As Long | ||
- | low = LBound(oArrWithCrit) | ||
- | Dim high As Long | ||
- | high = UBound(oArrWithCrit) | ||
- | Dim i As Long | ||
- | Dim result As Boolean | ||
- | ArrayFindEx = vNotFoundValue | ||
- | Do While low <= high | ||
- | i = (low + high) / 2 | ||
- | If vCrit = oArrWithCrit(i, | ||
- | ArrayFindEx = vFoundValue | ||
- | Exit Do | ||
- | ElseIf vCrit < oArrWithCrit(i, | ||
- | high = (i - 1) | ||
- | Else | ||
- | low = (i + 1) | ||
- | End If | ||
- | Loop | ||
- | | ||
- | End Function | ||
- | |||
- | |||
- | |||
- | ' | ||
- | Function RangeCountIf(oRngWithCrit As Range, vCrit As Variant) | ||
- | Dim vArr1 As Variant | ||
- | Dim lRow As Long | ||
- | | ||
- | vArr1 = oRngWithCrit.Value | ||
- | For lRow = LBound(vArr1, | ||
- | If vArr1(lRow, 1) = vCrit Then | ||
- | RangeCountIf = RangeCountIf + 1 | ||
- | End If | ||
- | Next | ||
- | | ||
- | | ||
- | ' Clear all objects. | ||
- | Set vArr1 = Nothing | ||
- | |||
- | End Function | ||
- | |||
- | |||
- | ' | ||
- | Function RangeSumIf(oRngWithCrit As Range, vCrit As Variant, oRngWithValues As Range) | ||
- | Dim vArr1 As Variant | ||
- | Dim vArr2 As Variant | ||
- | Dim lRow As Long | ||
- | If oRngWithCrit.Rows.Count = oRngWithValues.Rows.Count Then | ||
- | vArr1 = oRngWithCrit.Value | ||
- | vArr2 = oRngWithValues.Value | ||
- | For lRow = LBound(vArr1, | ||
- | If vArr1(lRow, 1) = vCrit Then | ||
- | RangeSumIf = ArraySumIf + vArr2(lRow, 1) | ||
- | End If | ||
- | Next | ||
- | Else | ||
- | RangeSumIf = " | ||
- | End If | ||
- | | ||
- | | ||
- | ' Clear all objects. | ||
- | Set vArr1 = Nothing | ||
- | Set vArr2 = Nothing | ||
- | |||
- | End Function | ||
- | |||
- | |||
- | |||
- | |||
- | ' Speedy - copies using arrays. | ||
- | ' Copies remaining formulae down on the SHEETNAME1 sheet. | ||
- | Sub M10535_Copy_Post_SHEETNAME1_Formulae_Down_Array() | ||
- | |||
- | Dim lastrow_CUST As Long | ||
- | Dim lastrow_SHEETNAME1 As Long | ||
- | Dim lastrow_FinalABC As Long | ||
- | Dim lastrow_HOLDINGS As Long | ||
- | Dim lastrow_MappingPivots As Long | ||
- | Dim lastrow_MappingPivots2 As Long | ||
- | Dim lastrow_MappingPivots3 As Long | ||
- | Dim lastrow_References As Long | ||
- | Dim lastrow_References_adjusted_rate As Long | ||
- | Dim lastrow_References_g3_location As Long | ||
- | Dim lastrow_References_income_type As Long | ||
- | Dim lastrow_References_allowed_locations As Long | ||
- | Dim lastrow_QSHEET As Long | ||
- | Dim lastrow_TRANSACTIONS As Long | ||
- | Dim lastrow_Wxxxx As Long | ||
- | |||
- | Dim column_a As Variant | ||
- | Dim column_b As Variant | ||
- | Dim column_e As Variant | ||
- | Dim column_f As Variant | ||
- | Dim column_g As Variant | ||
- | Dim column_h As Variant | ||
- | Dim column_i As Variant | ||
- | Dim column_k As Variant | ||
- | Dim column_l As Variant | ||
- | Dim column_m As Variant | ||
- | Dim column_n As Variant | ||
- | Dim column_p As Variant | ||
- | Dim column_r As Variant | ||
- | Dim column_t As Variant | ||
- | Dim column_u As Variant | ||
- | Dim column_x As Variant | ||
- | Dim column_y As Variant | ||
- | Dim column_ab As Variant | ||
- | Dim column_ad As Variant | ||
- | Dim column_af As Variant | ||
- | Dim column_ai As Variant | ||
- | Dim column_aj As Variant | ||
- | Dim column_am As Variant | ||
- | Dim column_an As Variant | ||
- | Dim column_ao As Variant | ||
- | Dim column_aq As Variant | ||
- | Dim column_ar As Variant | ||
- | Dim column_au As Variant | ||
- | Dim column_aw As Variant | ||
- | Dim column_bb As Variant | ||
- | Dim column_bd As Variant | ||
- | Dim column_bh As Variant | ||
- | | ||
- | Dim column_a_CUST As Variant | ||
- | Dim column_b_CUST As Variant | ||
- | Dim column_a_FinalABC As Variant | ||
- | Dim column_d_FinalABC As Variant | ||
- | Dim column_k_FinalABC As Variant | ||
- | Dim column_n_FinalABC As Variant | ||
- | Dim column_a_HOLDINGS As Variant | ||
- | Dim column_f_HOLDINGS As Variant | ||
- | Dim column_a_MappingPivots As Variant | ||
- | Dim column_b_MappingPivots As Variant | ||
- | Dim column_c_MappingPivots As Variant | ||
- | Dim column_d_MappingPivots As Variant | ||
- | Dim column_f_MappingPivots As Variant | ||
- | Dim column_g_MappingPivots As Variant | ||
- | Dim column_h_MappingPivots As Variant | ||
- | Dim column_i_MappingPivots As Variant | ||
- | Dim column_k_MappingPivots As Variant | ||
- | Dim column_m_MappingPivots As Variant | ||
- | Dim column_a_QSHEET As Variant | ||
- | Dim column_a_References As Variant | ||
- | Dim column_b_References As Variant | ||
- | Dim column_h_References As Variant | ||
- | Dim column_i_References As Variant | ||
- | Dim column_j_References As Variant | ||
- | Dim column_k_References As Variant | ||
- | Dim column_o_References As Variant | ||
- | Dim column_p_References As Variant | ||
- | Dim column_q_References As Variant | ||
- | Dim column_s_References As Variant | ||
- | Dim column_u_References As Variant | ||
- | Dim column_ag_References As Variant | ||
- | Dim column_a_TRANSACTIONS As Variant | ||
- | Dim column_l_TRANSACTIONS As Variant | ||
- | Dim column_m_TRANSACTIONS As Variant | ||
- | Dim column_n_TRANSACTIONS As Variant | ||
- | Dim column_b_Wxxxx As Variant | ||
- | Dim column_y_Wxxxx As Variant | ||
- | Dim column_z_Wxxxx As Variant | ||
- | | ||
- | Dim prev_a As Variant | ||
- | Dim prev_b As Variant | ||
- | Dim prev_c As Variant | ||
- | Dim prev_d As Variant | ||
- | Dim prev_f As Variant | ||
- | Dim prev_g As Variant | ||
- | Dim prev_h As Variant | ||
- | Dim prev_i As Variant | ||
- | | ||
- | Dim tmp As Variant | ||
- | | ||
- | Dim working As Variant | ||
- | Dim n As Long | ||
- | |||
- | |||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | | ||
- | | ||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | ' Update StatusBar. | ||
- | Application.StatusBar = "Copy post-SHEETNAME1 Formulae down..." | ||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | | ||
- | With .Sheets(" | ||
- | |||
- | ' Activate the SHEETNAME1 sheet. | ||
- | .Activate | ||
- | |||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_SHEETNAME1 = .Cells(Rows.Count, | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_SHEETNAME1 < 3 Then | ||
- | lastrow_SHEETNAME1 = 3 | ||
- | End If | ||
- | |||
- | lastrow_CUST = Sheets(" | ||
- | lastrow_FinalABC = Sheets(" | ||
- | lastrow_HOLDINGS = Sheets(" | ||
- | lastrow_MappingPivots = Sheets(" | ||
- | lastrow_MappingPivots2 = Sheets(" | ||
- | lastrow_MappingPivots3 = Sheets(" | ||
- | lastrow_References = Sheets(" | ||
- | lastrow_References_adjusted_rate = Sheets(" | ||
- | lastrow_References_g3_location = Sheets(" | ||
- | lastrow_References_income_type = Sheets(" | ||
- | lastrow_References_allowed_locations = Sheets(" | ||
- | lastrow_QSHEET = Sheets(" | ||
- | lastrow_TRANSACTIONS = Sheets(" | ||
- | lastrow_Wxxxx = Sheets(" | ||
- | | ||
- | | ||
- | ReDim working(1 To lastrow_SHEETNAME1, | ||
- | working = Range(" | ||
- | | ||
- | ReDim column_a(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_b(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_e(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_f(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_g(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_h(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_i(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_k(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_l(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_m(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_n(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_p(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_r(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_t(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_u(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_x(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_y(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_ab(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_ad(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_af(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_ai(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_aj(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_am(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_an(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_ao(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_aq(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_ar(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_au(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_aw(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_bd(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_bh(1 To lastrow_SHEETNAME1, | ||
- | | ||
- | ReDim column_a_CUST(1 To lastrow_CUST, | ||
- | ReDim column_b_CUST(1 To lastrow_CUST, | ||
- | ReDim column_a_FinalABC(1 To lastrow_FinalABC, | ||
- | ReDim column_d_FinalABC(1 To lastrow_FinalABC, | ||
- | ReDim column_k_FinalABC(1 To lastrow_FinalABC, | ||
- | ReDim column_n_FinalABC(1 To lastrow_FinalABC, | ||
- | ReDim column_a_HOLDINGS(1 To lastrow_HOLDINGS, | ||
- | ReDim column_f_HOLDINGS(1 To lastrow_HOLDINGS, | ||
- | ReDim column_a_MappingPivots(1 To lastrow_MappingPivots, | ||
- | ReDim column_b_MappingPivots(1 To lastrow_MappingPivots, | ||
- | ReDim column_c_MappingPivots(1 To lastrow_MappingPivots, | ||
- | ReDim column_d_MappingPivots(1 To lastrow_MappingPivots, | ||
- | ReDim column_f_MappingPivots(1 To lastrow_MappingPivots, | ||
- | ReDim column_g_MappingPivots(1 To lastrow_MappingPivots, | ||
- | ReDim column_h_MappingPivots(1 To lastrow_MappingPivots, | ||
- | ReDim column_i_MappingPivots(1 To lastrow_MappingPivots, | ||
- | ReDim column_m_MappingPivots(1 To lastrow_MappingPivots, | ||
- | ReDim column_k_MappingPivots(1 To lastrow_MappingPivots, | ||
- | ReDim column_a_References(1 To lastrow_References, | ||
- | ReDim column_b_References(1 To lastrow_References, | ||
- | ReDim column_h_References(1 To lastrow_References, | ||
- | ReDim column_i_References(1 To lastrow_References, | ||
- | ReDim column_j_References(1 To lastrow_References, | ||
- | ReDim column_k_References(1 To lastrow_References, | ||
- | ReDim column_o_References(1 To lastrow_References, | ||
- | ReDim column_p_References(1 To lastrow_References, | ||
- | ReDim column_q_References(1 To lastrow_References, | ||
- | ReDim column_s_References(1 To lastrow_References, | ||
- | ReDim column_u_References(1 To lastrow_References, | ||
- | ReDim column_ag_References(1 To lastrow_References, | ||
- | ReDim column_a_QSHEET(1 To lastrow_QSHEET, | ||
- | ReDim column_a_TRANSACTIONS(1 To lastrow_TRANSACTIONS, | ||
- | ReDim column_l_TRANSACTIONS(1 To lastrow_TRANSACTIONS, | ||
- | ReDim column_m_TRANSACTIONS(1 To lastrow_TRANSACTIONS, | ||
- | ReDim column_n_TRANSACTIONS(1 To lastrow_TRANSACTIONS, | ||
- | ReDim column_b_Wxxxx(1 To lastrow_Wxxxx, | ||
- | ReDim column_y_Wxxxx(1 To lastrow_Wxxxx, | ||
- | ReDim column_z_Wxxxx(1 To lastrow_Wxxxx, | ||
- | |||
- | |||
- | | ||
- | ' Column F | ||
- | ' =IF(X2=" | ||
- | column_g = Range(" | ||
- | column_y = Range(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | If (column_y(n, | ||
- | working(n, 1) = 0 | ||
- | Else | ||
- | working(n, 1) = column_g(n, 1) | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Column H | ||
- | ' =G2-I2 | ||
- | column_g = Range(" | ||
- | column_i = Range(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | working(n, 1) = column_g(n, 1) - column_i(n, 1) | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Column J | ||
- | ' =IF(K2="", | ||
- | column_k = Range(" | ||
- | column_i = Range(" | ||
- | column_l = Range(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | If column_k(n, 1) = "" | ||
- | working(n, 1) = column_i(n, 1) | ||
- | Else | ||
- | If column_l(n, 1) = "" | ||
- | working(n, 1) = column_i(n, 1) | ||
- | Else | ||
- | working(n, 1) = column_i(n, 1) / (column_l(n, | ||
- | End If | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | | ||
- | ' Column L | ||
- | ' =IF(G2=0, | ||
- | column_g = Range(" | ||
- | column_i = Range(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | If column_g(n, 1) = 0 Then ' Cant SHEETNAME1de by zero. | ||
- | working(n, 1) = 0 | ||
- | Else | ||
- | working(n, 1) = column_i(n, 1) / column_g(n, 1) | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Column M | ||
- | ' =VLOOKUP(U2, | ||
- | column_a_References = Sheets(" | ||
- | column_u = Range(" | ||
- | column_b_References = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | working(n, 1) = ArrayFind(column_a_References, | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Column T | ||
- | ' =VLOOKUP(R2, | ||
- | column_r = Range(" | ||
- | column_a_CUST = Sheets(" | ||
- | column_b_CUST = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | working(n, 1) = ArrayFind(column_a_CUST, | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Column V | ||
- | ' =IF(ISNA(VLOOKUP(B2, | ||
- | column_b = Range(" | ||
- | column_d_FinalABC = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | working(n, 1) = ArrayFindEx(column_d_FinalABC, | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Column W | ||
- | ' =B2=B1 | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | ' | ||
- | | ||
- | | ||
- | ' Column X | ||
- | ' =IF(ISNA(VLOOKUP(A2, | ||
- | column_a = Range(" | ||
- | column_a_FinalABC = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | working(n, 1) = ArrayFindEx(column_a_FinalABC, | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Column AB | ||
- | ' =IF(OR(X2=" | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_a = Range(" | ||
- | column_f = Range(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | working(n, 1) = column_a(n, 1) & " - " & Round(column_f(n, | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Column AC | ||
- | ' =IF(OR($X2=" | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_a = Range(" | ||
- | column_ab = Range(" | ||
- | column_a_MappingPivots = Sheets(" | ||
- | column_b_MappingPivots = Sheets(" | ||
- | column_f_MappingPivots = Sheets(" | ||
- | column_g_MappingPivots = Sheets(" | ||
- | | ||
- | ' Tidy up for Mapping Pivots columns. | ||
- | ' This effects binary searches, so initially in the columns if a blank is encountered then actual value | ||
- | ' is written in its place. | ||
- | prev_a = column_a_MappingPivots(LBound(column_a_MappingPivots), | ||
- | prev_b = column_b_MappingPivots(LBound(column_b_MappingPivots), | ||
- | For n = LBound(column_a_MappingPivots) To UBound(column_a_MappingPivots) | ||
- | If column_a_MappingPivots(n, | ||
- | column_a_MappingPivots(n, | ||
- | End If | ||
- | If column_b_MappingPivots(n, | ||
- | column_b_MappingPivots(n, | ||
- | End If | ||
- | prev_a = column_a_MappingPivots(n, | ||
- | prev_b = column_b_MappingPivots(n, | ||
- | Next n | ||
- | | ||
- | prev_f = column_f_MappingPivots(LBound(column_f_MappingPivots), | ||
- | prev_g = column_g_MappingPivots(LBound(column_g_MappingPivots), | ||
- | For n = LBound(column_f_MappingPivots) To UBound(column_f_MappingPivots) | ||
- | If column_f_MappingPivots(n, | ||
- | column_f_MappingPivots(n, | ||
- | End If | ||
- | If column_g_MappingPivots(n, | ||
- | column_g_MappingPivots(n, | ||
- | End If | ||
- | prev_f = column_f_MappingPivots(n, | ||
- | prev_g = column_g_MappingPivots(n, | ||
- | Next n | ||
- | | ||
- | For n = LBound(working) To UBound(working) | ||
- | |||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | If ArrayCountIf(column_a_MappingPivots, | ||
- | working(n, 1) = ArrayFind(column_a_MappingPivots, | ||
- | Else | ||
- | If ArrayCountIf(column_f_MappingPivots, | ||
- | working(n, 1) = ArrayFind(column_f_MappingPivots, | ||
- | Else | ||
- | working(n, 1) = " | ||
- | End If | ||
- | End If | ||
- | End If | ||
- | Next n | ||
- | |||
- | .Range(" | ||
- | | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | | ||
- | ' Column AE | ||
- | ' =IF(OR($X2=" | ||
- | | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_a = Range(" | ||
- | column_ab = Range(" | ||
- | column_a_MappingPivots = Sheets(" | ||
- | column_c_MappingPivots = Sheets(" | ||
- | column_f_MappingPivots = Sheets(" | ||
- | column_h_MappingPivots = Sheets(" | ||
- | | ||
- | ' Tidy up for Mapping Pivots columns. | ||
- | ' This effects binary searches, so initially in the columns if a blank is encountered then actual value | ||
- | ' is written in its place. | ||
- | prev_a = column_a_MappingPivots(LBound(column_a_MappingPivots), | ||
- | prev_c = column_c_MappingPivots(LBound(column_c_MappingPivots), | ||
- | For n = LBound(column_a_MappingPivots) To UBound(column_a_MappingPivots) | ||
- | If column_a_MappingPivots(n, | ||
- | column_a_MappingPivots(n, | ||
- | End If | ||
- | If column_c_MappingPivots(n, | ||
- | column_c_MappingPivots(n, | ||
- | End If | ||
- | prev_a = column_a_MappingPivots(n, | ||
- | prev_c = column_c_MappingPivots(n, | ||
- | Next n | ||
- | | ||
- | prev_f = column_f_MappingPivots(LBound(column_f_MappingPivots), | ||
- | prev_h = column_h_MappingPivots(LBound(column_h_MappingPivots), | ||
- | For n = LBound(column_f_MappingPivots) To UBound(column_f_MappingPivots) | ||
- | If column_f_MappingPivots(n, | ||
- | column_f_MappingPivots(n, | ||
- | End If | ||
- | If column_h_MappingPivots(n, | ||
- | column_h_MappingPivots(n, | ||
- | End If | ||
- | prev_f = column_f_MappingPivots(n, | ||
- | prev_h = column_h_MappingPivots(n, | ||
- | Next n | ||
- | |||
- | For n = LBound(working) To UBound(working) | ||
- | |||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | If ArrayCountIf(column_a_MappingPivots, | ||
- | working(n, 1) = ArrayFind(column_a_MappingPivots, | ||
- | Else | ||
- | If ArrayCountIf(column_f_MappingPivots, | ||
- | working(n, 1) = ArrayFind(column_f_MappingPivots, | ||
- | Else | ||
- | working(n, 1) = " | ||
- | End If | ||
- | End If | ||
- | End If | ||
- | Next n | ||
- | |||
- | .Range(" | ||
- | | ||
- | | ||
- | | ||
- | ' Column AG | ||
- | ' =IF(OR($X2=" | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_a = Range(" | ||
- | column_i = Range(" | ||
- | column_a_FinalABC = Sheets(" | ||
- | column_n_FinalABC = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | If ArrayCountIf(column_a, | ||
- | working(n, 1) = " | ||
- | Else | ||
- | working(n, 1) = Round(ArraySumIf(column_a, | ||
- | End If | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | | ||
- | ' Column AH | ||
- | ' =IF(AG2=" | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_a = Range(" | ||
- | column_i = Range(" | ||
- | column_a_FinalABC = Sheets(" | ||
- | column_n_FinalABC = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_x(n, | ||
- | 'If working(n, 1) = "NON REPORTABLE" | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | If (column_y(n, | ||
- | working(n, 1) = Round(ArraySumIf(column_a, | ||
- | | ||
- | If ((working(n, | ||
- | working(n, 1) = column_k(n, 1) | ||
- | Else | ||
- | working(n, 1) = " | ||
- | End If | ||
- | Else | ||
- | working(n, 1) = " | ||
- | End If | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Copy adjustment data. | ||
- | ' | ||
- | | ||
- | | ||
- | ' Column AJ | ||
- | ' =IF(OR($X2=" | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_e = Range(" | ||
- | column_ai = Range(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | If IsNumeric(column_ai(n, | ||
- | working(n, 1) = Round(column_e(n, | ||
- | Else | ||
- | working(n, 1) = 0 | ||
- | End If | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Column AK | ||
- | ' =IF(OR($X2=" | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_a = Range(" | ||
- | column_aj = Range(" | ||
- | column_a_FinalABC = Sheets(" | ||
- | column_n_FinalABC = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | ' | ||
- | working(n, 1) = ArraySumIf(column_a, | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | | ||
- | ' Column AL | ||
- | ' =IF(OR($X2=" | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_a = Range(" | ||
- | column_ab = Range(" | ||
- | column_a_MappingPivots = Sheets(" | ||
- | column_d_MappingPivots = Sheets(" | ||
- | column_f_MappingPivots = Sheets(" | ||
- | column_i_MappingPivots = Sheets(" | ||
- | | ||
- | ' Tidy up for Mapping Pivots columns. | ||
- | ' This effects binary searches, so initially in the columns if a blank is encountered then actual value | ||
- | ' is written in its place. | ||
- | prev_a = column_a_MappingPivots(LBound(column_a_MappingPivots), | ||
- | prev_d = column_d_MappingPivots(LBound(column_d_MappingPivots), | ||
- | For n = LBound(column_a_MappingPivots) To UBound(column_a_MappingPivots) | ||
- | If column_a_MappingPivots(n, | ||
- | column_a_MappingPivots(n, | ||
- | End If | ||
- | If column_d_MappingPivots(n, | ||
- | column_d_MappingPivots(n, | ||
- | End If | ||
- | prev_a = column_a_MappingPivots(n, | ||
- | prev_d = column_d_MappingPivots(n, | ||
- | Next n | ||
- | | ||
- | prev_f = column_f_MappingPivots(LBound(column_f_MappingPivots), | ||
- | prev_i = column_i_MappingPivots(LBound(column_i_MappingPivots), | ||
- | For n = LBound(column_f_MappingPivots) To UBound(column_f_MappingPivots) | ||
- | If column_f_MappingPivots(n, | ||
- | column_f_MappingPivots(n, | ||
- | End If | ||
- | If column_i_MappingPivots(n, | ||
- | column_i_MappingPivots(n, | ||
- | End If | ||
- | prev_f = column_f_MappingPivots(n, | ||
- | prev_i = column_i_MappingPivots(n, | ||
- | Next n | ||
- | |||
- | For n = LBound(working) To UBound(working) | ||
- | |||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | If ArrayCountIf(column_a_MappingPivots, | ||
- | working(n, 1) = ArrayFind(column_a_MappingPivots, | ||
- | Else | ||
- | If ArrayCountIf(column_f_MappingPivots, | ||
- | working(n, 1) = ArrayFind(column_f_MappingPivots, | ||
- | Else | ||
- | working(n, 1) = " | ||
- | End If | ||
- | End If | ||
- | End If | ||
- | Next n | ||
- | |||
- | .Range(" | ||
- | | ||
- | | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Copy adjustment data. | ||
- | ' | ||
- | | ||
- | | ||
- | ' Column AN | ||
- | ' =IF(OR($X2=" | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_a = Range(" | ||
- | column_am = Range(" | ||
- | column_k_MappingPivots = Sheets(" | ||
- | column_m_MappingPivots = Sheets(" | ||
- | |||
- | For n = LBound(working) To UBound(working) | ||
- | |||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | working(n, 1) = ArrayFind(column_k_MappingPivots, | ||
- | End If | ||
- | | ||
- | Next n | ||
- | |||
- | .Range(" | ||
- | |||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | | ||
- | ' Column AO | ||
- | ' =IF(OR($X2=" | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_f = Range(" | ||
- | column_an = Range(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | If (column_an(n, | ||
- | working(n, 1) = 0 | ||
- | Else | ||
- | working(n, 1) = column_f(n, 1) / column_an(n, | ||
- | End If | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Column AP | ||
- | ' =IF(OR($X2=" | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_a = Range(" | ||
- | column_ao = Range(" | ||
- | column_a_FinalABC = Sheets(" | ||
- | column_k_FinalABC = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | If ArrayCountIf(column_a, | ||
- | working(n, 1) = " | ||
- | Else | ||
- | working(n, 1) = Round(ArraySumIf(column_a, | ||
- | End If | ||
- | End If | ||
- | Next n | ||
- | |||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Column AQ | ||
- | ' =IF(OR($X2=" | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_t = Range(" | ||
- | column_u = Range(" | ||
- | column_b_Wxxxx = Sheets(" | ||
- | column_y_Wxxxx = Sheets(" | ||
- | column_r = Range(" | ||
- | column_z_Wxxxx = Sheets(" | ||
- | column_k = Range(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | working(n, 1) = column_t(n, 1) & " - " | ||
- | | ||
- | tmp = ArrayFind(column_b_Wxxxx, | ||
- | If tmp = " | ||
- | working(n, 1) = working(n, 1) & " | ||
- | Else | ||
- | working(n, 1) = working(n, 1) & " | ||
- | End If | ||
- | | ||
- | tmp = ArrayFind(column_b_Wxxxx, | ||
- | working(n, 1) = working(n, 1) & tmp & " - " & column_k(n, 1) | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Column AR | ||
- | ' =IF(OR($X2=" | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_aq = Range(" | ||
- | column_h_References = Sheets(" | ||
- | column_i_References = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | working(n, 1) = ArrayFind(column_h_References, | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Column AS | ||
- | ' =IF(OR($X2=" | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_aq = Range(" | ||
- | column_h_References = Sheets(" | ||
- | column_j_References = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | working(n, 1) = ArrayFind(column_h_References, | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Column AT | ||
- | ' =IF(OR($X2=" | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_aq = Range(" | ||
- | column_h_References = Sheets(" | ||
- | column_k_References = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | working(n, 1) = ArrayFind(column_h_References, | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Copy adjustment data. | ||
- | ' | ||
- | | ||
- | | ||
- | ' Column AV | ||
- | ' =IF(OR($X2=" | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_ad = Range(" | ||
- | column_af = Range(" | ||
- | column_s_References = Sheets(" | ||
- | column_u_References = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | working(n, 1) = ArrayFind(column_s_References, | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Column AW | ||
- | ' =IF(OR($X2=" | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_ar = Range(" | ||
- | column_k = Range(" | ||
- | column_au = Range(" | ||
- | column_ai = Range(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | If (column_ar(n, | ||
- | working(n, 1) = "NO ADJUSTMENT REQUIRED" | ||
- | Else | ||
- | working(n, 1) = " | ||
- | End If | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Column AX | ||
- | ' =IF(OR($X2=" | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_r = Range(" | ||
- | column_t = Range(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | If (column_r(n, | ||
- | working(n, 1) = " | ||
- | Else | ||
- | If (column_t(n, | ||
- | working(n, 1) = " | ||
- | Else | ||
- | working(n, 1) = " | ||
- | End If | ||
- | End If | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Column AY | ||
- | ' =IF(AW2=" | ||
- | column_aw = Range(" | ||
- | column_f = Range(" | ||
- | column_au = Range(" | ||
- | column_i = Range(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_aw(n, | ||
- | working(n, 1) = "NO ADJUSTMENT REQUIRED" | ||
- | Else | ||
- | If (column_aw(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | working(n, 1) = Round((column_f(n, | ||
- | End If | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Column BB | ||
- | ' =IF(ISNA(VLOOKUP(U2, | ||
- | column_u = Range(" | ||
- | column_ag_References = Sheets(" | ||
- | column_aw = Range(" | ||
- | column_t = Range(" | ||
- | column_au = Range(" | ||
- | column_o_References = Sheets(" | ||
- | column_q_References = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If ArrayCountIf(column_ag_References, | ||
- | If column_aw(n, | ||
- | working(n, 1) = "NO ADJUSTMENT REQUIRED" | ||
- | Else | ||
- | If column_aw(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | working(n, 1) = ArrayFind(column_o_References, | ||
- | End If | ||
- | | ||
- | End If | ||
- | ' | ||
- | Else | ||
- | working(n, 1) = "NO ADJUSTMENT REQUIRED" | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Column BD | ||
- | ' =IF(AW2=" | ||
- | column_aw = Range(" | ||
- | column_au = Range(" | ||
- | column_o_References = Sheets(" | ||
- | column_p_References = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_aw(n, | ||
- | working(n, 1) = "NO ADJUSTMENT REQUIRED" | ||
- | Else | ||
- | If (column_aw(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | working(n, 1) = ArrayFind(column_o_References, | ||
- | End If | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Column BE | ||
- | ' | ||
- | column_aw = Range(" | ||
- | column_bd = Range(" | ||
- | column_m = Range(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_aw(n, | ||
- | working(n, 1) = "NO ADJUSTMENT REQUIRED" | ||
- | Else | ||
- | If (column_aw(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | If (column_bd(n, | ||
- | working(n, 1) = " | ||
- | Else | ||
- | working(n, 1) = " | ||
- | End If | ||
- | End If | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Column BG | ||
- | ' =IF(ISNA(VLOOKUP(R2& | ||
- | column_r = Range(" | ||
- | column_n = Range(" | ||
- | column_a_HOLDINGS = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | ' | ||
- | working(n, 1) = ArrayFindEx(column_a_HOLDINGS, | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | |||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Column BH | ||
- | ' | ||
- | column_r = Range(" | ||
- | column_n = Range(" | ||
- | column_a_HOLDINGS = Sheets(" | ||
- | column_f_HOLDINGS = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | working(n, 1) = ArrayFind(column_a_HOLDINGS, | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Column BI | ||
- | ' =IF(BH2=" | ||
- | column_bh = Range(" | ||
- | column_a_References = Sheets(" | ||
- | column_b_References = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | If column_bh(n, | ||
- | working(n, 1) = "NO HOLDINGS" | ||
- | Else | ||
- | working(n, 1) = ArrayFind(column_a_References, | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Column BJ | ||
- | ' =IF(OR(BB2=" | ||
- | column_bb = Range(" | ||
- | column_y = Range(" | ||
- | column_p = Range(" | ||
- | column_h = Range(" | ||
- | column_r = Range(" | ||
- | column_a_TRANSACTIONS = Sheets(" | ||
- | column_l_TRANSACTIONS = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | If column_bb(n, | ||
- | working(n, 1) = "NO ADJUSTMENT REQUIRED" | ||
- | Else | ||
- | working(n, 1) = ArrayFind(column_a_TRANSACTIONS, | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Column BK | ||
- | ' =IF(OR(BB2=" | ||
- | column_bb = Range(" | ||
- | column_y = Range(" | ||
- | column_p = Range(" | ||
- | column_h = Range(" | ||
- | column_r = Range(" | ||
- | column_a_TRANSACTIONS = Sheets(" | ||
- | column_m_TRANSACTIONS = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | If column_bb(n, | ||
- | working(n, 1) = "NO ADJUSTMENT REQUIRED" | ||
- | Else | ||
- | working(n, 1) = ArrayFind(column_a_TRANSACTIONS, | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Column BL | ||
- | ' =IF(OR(BB2=" | ||
- | column_bb = Range(" | ||
- | column_y = Range(" | ||
- | column_p = Range(" | ||
- | column_h = Range(" | ||
- | column_r = Range(" | ||
- | column_a_TRANSACTIONS = Sheets(" | ||
- | column_n_TRANSACTIONS = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | If column_bb(n, | ||
- | working(n, 1) = "NO ADJUSTMENT REQUIRED" | ||
- | Else | ||
- | working(n, 1) = ArrayFind(column_a_TRANSACTIONS, | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Column BM | ||
- | ' =IF(ISNA(VLOOKUP(R2, | ||
- | column_r = Range(" | ||
- | column_a_QSHEET = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | working(n, 1) = ArrayFindEx(column_a_QSHEET, | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | End With | ||
- | End With | ||
- | |||
- | |||
- | ' Clear all objects. | ||
- | Set working = Nothing | ||
- | | ||
- | Set column_a = Nothing | ||
- | Set column_b = Nothing | ||
- | Set column_e = Nothing | ||
- | Set column_f = Nothing | ||
- | Set column_g = Nothing | ||
- | Set column_h = Nothing | ||
- | Set column_i = Nothing | ||
- | Set column_k = Nothing | ||
- | Set column_l = Nothing | ||
- | Set column_m = Nothing | ||
- | Set column_n = Nothing | ||
- | Set column_p = Nothing | ||
- | Set column_r = Nothing | ||
- | Set column_t = Nothing | ||
- | Set column_u = Nothing | ||
- | Set column_x = Nothing | ||
- | Set column_y = Nothing | ||
- | Set column_ab = Nothing | ||
- | Set column_ad = Nothing | ||
- | Set column_af = Nothing | ||
- | Set column_ai = Nothing | ||
- | Set column_aj = Nothing | ||
- | Set column_am = Nothing | ||
- | Set column_an = Nothing | ||
- | Set column_ao = Nothing | ||
- | Set column_aq = Nothing | ||
- | Set column_ar = Nothing | ||
- | Set column_au = Nothing | ||
- | Set column_aw = Nothing | ||
- | Set column_bb = Nothing | ||
- | Set column_bd = Nothing | ||
- | Set column_bh = Nothing | ||
- | | ||
- | Set column_a_CUST = Nothing | ||
- | Set column_b_CUST = Nothing | ||
- | Set column_a_FinalABC = Nothing | ||
- | Set column_d_FinalABC = Nothing | ||
- | Set column_k_FinalABC = Nothing | ||
- | Set column_n_FinalABC = Nothing | ||
- | Set column_a_HOLDINGS = Nothing | ||
- | Set column_f_HOLDINGS = Nothing | ||
- | Set column_a_MappingPivots = Nothing | ||
- | Set column_b_MappingPivots = Nothing | ||
- | Set column_c_MappingPivots = Nothing | ||
- | Set column_d_MappingPivots = Nothing | ||
- | Set column_f_MappingPivots = Nothing | ||
- | Set column_g_MappingPivots = Nothing | ||
- | Set column_h_MappingPivots = Nothing | ||
- | Set column_i_MappingPivots = Nothing | ||
- | Set column_k_MappingPivots = Nothing | ||
- | Set column_m_MappingPivots = Nothing | ||
- | Set column_a_QSHEET = Nothing | ||
- | Set column_a_References = Nothing | ||
- | Set column_b_References = Nothing | ||
- | Set column_h_References = Nothing | ||
- | Set column_i_References = Nothing | ||
- | Set column_j_References = Nothing | ||
- | Set column_k_References = Nothing | ||
- | Set column_o_References = Nothing | ||
- | Set column_p_References = Nothing | ||
- | Set column_q_References = Nothing | ||
- | Set column_s_References = Nothing | ||
- | Set column_u_References = Nothing | ||
- | Set column_ag_References = Nothing | ||
- | | ||
- | Set column_a_TRANSACTIONS = Nothing | ||
- | Set column_l_TRANSACTIONS = Nothing | ||
- | Set column_m_TRANSACTIONS = Nothing | ||
- | Set column_n_TRANSACTIONS = Nothing | ||
- | Set column_b_Wxxxx = Nothing | ||
- | Set column_y_Wxxxx = Nothing | ||
- | Set column_z_Wxxxx = Nothing | ||
- | | ||
- | Set prev_a = Nothing | ||
- | Set prev_b = Nothing | ||
- | Set prev_c = Nothing | ||
- | Set prev_f = Nothing | ||
- | Set prev_g = Nothing | ||
- | Set prev_h = Nothing | ||
- | Set prev_i = Nothing | ||
- | | ||
- | Set tmp = Nothing | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | |||
- | ' Copies remaining formulae down on the SHEETNAME1 sheet. | ||
- | Sub M10540_Copy_Post_SHEETNAME1_Formulae_Down() | ||
- | |||
- | Dim lastrow_SHEETNAME1 As Long | ||
- | |||
- | |||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | | ||
- | | ||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | ' Update StatusBar. | ||
- | Application.StatusBar = "Copy post-SHEETNAME1 Formulae down..." | ||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | | ||
- | With .Sheets(" | ||
- | |||
- | ' Activate the SHEETNAME1 sheet. | ||
- | .Activate | ||
- | |||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_SHEETNAME1 = .Cells(Rows.Count, | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_SHEETNAME1 < 3 Then | ||
- | lastrow_SHEETNAME1 = 3 | ||
- | End If | ||
- | |||
- | | ||
- | ' Copies formulae down. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | |||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | End With | ||
- | End With | ||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Now that both Final and SHEETNAME1 sheets populated, need to action some more formulae calculations. | ||
- | Sub M10600_Copy_More_FinalABC_Formulae_Down() | ||
- | |||
- | 'Dim mycell As Variant | ||
- | Dim lastrow_FinalABC As Long | ||
- | |||
- | |||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | | ||
- | | ||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | | ||
- | ' Update StatusBar. | ||
- | Application.StatusBar = "Copy more BBH Formulae down..." | ||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | |||
- | |||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_FinalABC = .Cells(Rows.Count, | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_FinalABC < 3 Then | ||
- | lastrow_FinalABC = 3 | ||
- | End If | ||
- | |||
- | |||
- | ' Copies formulae down. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | |||
- | |||
- | ' Calculations. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | |||
- | |||
- | ' Now copy and paste formula ranges as values to speed up the file processing. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | End With | ||
- | End With | ||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Adds 1 to the Corrected Date, column E, in the FinalABC sheet for dates that were the last date of the month. | ||
- | ' It then recalculates the sheet to determine if column AL now reconciles, i.e. shows " | ||
- | ' This requires the following columns to have formulae throughout: | ||
- | Sub M10610_Reformat_FinalABC_Corrected_Dates() | ||
- | |||
- | Dim lastrow_FinalABC As Long | ||
- | Dim cell_date As Date | ||
- | Dim LastDayOfMonth As Date | ||
- | Dim pt As PivotTable | ||
- | Dim i As Long | ||
- | |||
- | |||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | | ||
- | | ||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | |||
- | |||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_FinalABC = .Cells(Rows.Count, | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_FinalABC < 3 Then | ||
- | lastrow_FinalABC = 3 | ||
- | End If | ||
- | |||
- | |||
- | ' Loop through every row and where column AJ does not match, it then changes the date in column E to the | ||
- | ' 1st of the next month and again checks if column AJ matches. | ||
- | ' the newly calculated values. | ||
- | For i = 2 To lastrow_FinalABC | ||
- | If RTrim(LTrim(.Range(" | ||
- | | ||
- | cell_date = .Range(" | ||
- | LastDayOfMonth = DateSerial(Year(cell_date), | ||
- | |||
- | If cell_date = LastDayOfMonth Then | ||
- | | ||
- | ' Change for formula in column E to add 1 to the date. This should make dates that are the last day of the month now reflect | ||
- | ' the 1st of the following month. | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' If column AJ is unchanged then the change of the date did not work. So reset back. | ||
- | If RTrim(LTrim(Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | Else ' Column AJ has changed therefore change of date in column E has worked. | ||
- | | ||
- | If (i <> 2) Then ' Do not process for column 2 as we need to retain the formulae. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | End If | ||
- | | ||
- | End If | ||
- | | ||
- | End If | ||
- | |||
- | End If | ||
- | Next i | ||
- | | ||
- | End With | ||
- | |||
- | |||
- | ' Refresh Mapping Pivots | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Refresh all the pivot tables on the Mapping Pivots sheet. | ||
- | 'For Each Sheet In ThisWorkbook.Worksheets | ||
- | 'For Each Pivot In Sheet.PivotTables | ||
- | For Each pt In .PivotTables | ||
- | pt.RefreshTable | ||
- | pt.Update | ||
- | Next | ||
- | 'Next | ||
- | | ||
- | End With | ||
- | End With | ||
- | | ||
- | | ||
- | ' Clear all objects. | ||
- | Set pt = Nothing | ||
- | | ||
- | | ||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Speedy - copies using arrays. | ||
- | ' Copies remaining formulae down on the SHEETNAME1 sheet. | ||
- | Sub M10615_Recalc_SHEETNAME1_Formulae_Array() | ||
- | |||
- | Dim lastrow_CUST As Long | ||
- | Dim lastrow_SHEETNAME1 As Long | ||
- | Dim lastrow_FinalABC As Long | ||
- | Dim lastrow_HOLDINGS As Long | ||
- | Dim lastrow_MappingPivots As Long | ||
- | Dim lastrow_MappingPivots2 As Long | ||
- | Dim lastrow_MappingPivots3 As Long | ||
- | Dim lastrow_References As Long | ||
- | Dim lastrow_References_adjusted_rate As Long | ||
- | Dim lastrow_References_g3_location As Long | ||
- | Dim lastrow_References_income_type As Long | ||
- | Dim lastrow_References_allowed_locations As Long | ||
- | Dim lastrow_QSHEET As Long | ||
- | Dim lastrow_TRANSACTIONS As Long | ||
- | Dim lastrow_Wxxxx As Long | ||
- | |||
- | Dim column_a As Variant | ||
- | Dim column_b As Variant | ||
- | Dim column_e As Variant | ||
- | Dim column_f As Variant | ||
- | Dim column_g As Variant | ||
- | Dim column_h As Variant | ||
- | Dim column_i As Variant | ||
- | Dim column_k As Variant | ||
- | Dim column_m As Variant | ||
- | Dim column_n As Variant | ||
- | Dim column_p As Variant | ||
- | Dim column_r As Variant | ||
- | Dim column_t As Variant | ||
- | Dim column_u As Variant | ||
- | Dim column_x As Variant | ||
- | Dim column_y As Variant | ||
- | Dim column_ab As Variant | ||
- | Dim column_ad As Variant | ||
- | Dim column_af As Variant | ||
- | Dim column_ai As Variant | ||
- | Dim column_aj As Variant | ||
- | Dim column_am As Variant | ||
- | Dim column_an As Variant | ||
- | Dim column_ao As Variant | ||
- | Dim column_aq As Variant | ||
- | Dim column_ar As Variant | ||
- | Dim column_au As Variant | ||
- | Dim column_aw As Variant | ||
- | Dim column_bb As Variant | ||
- | Dim column_bd As Variant | ||
- | Dim column_bh As Variant | ||
- | | ||
- | Dim column_a_CUST As Variant | ||
- | Dim column_b_CUST As Variant | ||
- | Dim column_a_FinalABC As Variant | ||
- | Dim column_d_FinalABC As Variant | ||
- | Dim column_k_FinalABC As Variant | ||
- | Dim column_n_FinalABC As Variant | ||
- | Dim column_a_HOLDINGS As Variant | ||
- | Dim column_f_HOLDINGS As Variant | ||
- | Dim column_a_MappingPivots As Variant | ||
- | Dim column_b_MappingPivots As Variant | ||
- | Dim column_c_MappingPivots As Variant | ||
- | Dim column_d_MappingPivots As Variant | ||
- | Dim column_f_MappingPivots As Variant | ||
- | Dim column_g_MappingPivots As Variant | ||
- | Dim column_h_MappingPivots As Variant | ||
- | Dim column_i_MappingPivots As Variant | ||
- | Dim column_m_MappingPivots As Variant | ||
- | Dim column_k_MappingPivots As Variant | ||
- | Dim column_a_QSHEET As Variant | ||
- | Dim column_a_References As Variant | ||
- | Dim column_b_References As Variant | ||
- | Dim column_h_References As Variant | ||
- | Dim column_i_References As Variant | ||
- | Dim column_j_References As Variant | ||
- | Dim column_k_References As Variant | ||
- | Dim column_o_References As Variant | ||
- | Dim column_p_References As Variant | ||
- | Dim column_q_References As Variant | ||
- | Dim column_s_References As Variant | ||
- | Dim column_u_References As Variant | ||
- | Dim column_ag_References As Variant | ||
- | Dim column_a_TRANSACTIONS As Variant | ||
- | Dim column_l_TRANSACTIONS As Variant | ||
- | Dim column_m_TRANSACTIONS As Variant | ||
- | Dim column_n_TRANSACTIONS As Variant | ||
- | Dim column_b_Wxxxx As Variant | ||
- | Dim column_y_Wxxxx As Variant | ||
- | Dim column_z_Wxxxx As Variant | ||
- | | ||
- | Dim prev_a As Variant | ||
- | Dim prev_b As Variant | ||
- | Dim prev_c As Variant | ||
- | Dim prev_d As Variant | ||
- | Dim prev_f As Variant | ||
- | Dim prev_g As Variant | ||
- | Dim prev_h As Variant | ||
- | Dim prev_i As Variant | ||
- | | ||
- | Dim tmp As Variant | ||
- | | ||
- | Dim working As Variant | ||
- | Dim n As Long | ||
- | |||
- | |||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | | ||
- | | ||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | | ||
- | With .Sheets(" | ||
- | |||
- | ' Activate the SHEETNAME1 sheet. | ||
- | .Activate | ||
- | |||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_SHEETNAME1 = .Cells(Rows.Count, | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_SHEETNAME1 < 3 Then | ||
- | lastrow_SHEETNAME1 = 3 | ||
- | End If | ||
- | |||
- | lastrow_CUST = Sheets(" | ||
- | lastrow_FinalABC = Sheets(" | ||
- | lastrow_HOLDINGS = Sheets(" | ||
- | lastrow_MappingPivots = Sheets(" | ||
- | lastrow_MappingPivots2 = Sheets(" | ||
- | lastrow_MappingPivots3 = Sheets(" | ||
- | lastrow_References = Sheets(" | ||
- | lastrow_References_adjusted_rate = Sheets(" | ||
- | lastrow_References_g3_location = Sheets(" | ||
- | lastrow_References_income_type = Sheets(" | ||
- | lastrow_References_allowed_locations = Sheets(" | ||
- | lastrow_QSHEET = Sheets(" | ||
- | lastrow_TRANSACTIONS = Sheets(" | ||
- | lastrow_Wxxxx = Sheets(" | ||
- | | ||
- | | ||
- | ReDim working(1 To lastrow_SHEETNAME1, | ||
- | | ||
- | ReDim column_a(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_b(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_e(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_f(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_g(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_h(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_i(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_k(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_m(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_n(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_p(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_r(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_t(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_u(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_x(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_y(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_ab(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_ad(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_af(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_ai(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_aj(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_am(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_an(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_ao(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_aq(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_ar(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_au(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_aw(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_bd(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_bh(1 To lastrow_SHEETNAME1, | ||
- | | ||
- | ReDim column_a_CUST(1 To lastrow_CUST, | ||
- | ReDim column_b_CUST(1 To lastrow_CUST, | ||
- | ReDim column_a_FinalABC(1 To lastrow_FinalABC, | ||
- | ReDim column_d_FinalABC(1 To lastrow_FinalABC, | ||
- | ReDim column_k_FinalABC(1 To lastrow_FinalABC, | ||
- | ReDim column_n_FinalABC(1 To lastrow_FinalABC, | ||
- | ReDim column_a_HOLDINGS(1 To lastrow_HOLDINGS, | ||
- | ReDim column_g_HOLDINGS(1 To lastrow_HOLDINGS, | ||
- | ReDim column_a_MappingPivots(1 To lastrow_MappingPivots, | ||
- | ReDim column_b_MappingPivots(1 To lastrow_MappingPivots, | ||
- | ReDim column_c_MappingPivots(1 To lastrow_MappingPivots, | ||
- | ReDim column_d_MappingPivots(1 To lastrow_MappingPivots, | ||
- | ReDim column_f_MappingPivots(1 To lastrow_MappingPivots, | ||
- | ReDim column_g_MappingPivots(1 To lastrow_MappingPivots, | ||
- | ReDim column_h_MappingPivots(1 To lastrow_MappingPivots, | ||
- | ReDim column_i_MappingPivots(1 To lastrow_MappingPivots, | ||
- | ReDim column_m_MappingPivots(1 To lastrow_MappingPivots, | ||
- | ReDim column_k_MappingPivots(1 To lastrow_MappingPivots, | ||
- | ReDim column_a_References(1 To lastrow_References, | ||
- | ReDim column_b_References(1 To lastrow_References, | ||
- | ReDim column_h_References(1 To lastrow_References, | ||
- | ReDim column_i_References(1 To lastrow_References, | ||
- | ReDim column_j_References(1 To lastrow_References, | ||
- | ReDim column_k_References(1 To lastrow_References, | ||
- | ReDim column_o_References(1 To lastrow_References, | ||
- | ReDim column_p_References(1 To lastrow_References, | ||
- | ReDim column_q_References(1 To lastrow_References, | ||
- | ReDim column_s_References(1 To lastrow_References, | ||
- | ReDim column_u_References(1 To lastrow_References, | ||
- | ReDim column_ag_References(1 To lastrow_References, | ||
- | ReDim column_a_QSHEET(1 To lastrow_QSHEET, | ||
- | ReDim column_a_TRANSACTIONS(1 To lastrow_TRANSACTIONS, | ||
- | ReDim column_l_TRANSACTIONS(1 To lastrow_TRANSACTIONS, | ||
- | ReDim column_m_TRANSACTIONS(1 To lastrow_TRANSACTIONS, | ||
- | ReDim column_n_TRANSACTIONS(1 To lastrow_TRANSACTIONS, | ||
- | ReDim column_b_Wxxxx(1 To lastrow_Wxxxx, | ||
- | ReDim column_y_Wxxxx(1 To lastrow_Wxxxx, | ||
- | ReDim column_z_Wxxxx(1 To lastrow_Wxxxx, | ||
- | |||
- | working = Range(" | ||
- | |||
- | | ||
- | ' Column X | ||
- | ' =IF(ISNA(VLOOKUP(A2, | ||
- | column_a = Range(" | ||
- | column_a_FinalABC = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | working(n, 1) = ArrayFindEx(column_a_FinalABC, | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Column AB | ||
- | ' =IF(OR(X2=" | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_a = Range(" | ||
- | column_f = Range(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | working(n, 1) = column_a(n, 1) & " - " & Round(column_f(n, | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Column AC | ||
- | ' =IF(OR($X2=" | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_a = Range(" | ||
- | column_ab = Range(" | ||
- | column_a_MappingPivots = Sheets(" | ||
- | column_b_MappingPivots = Sheets(" | ||
- | column_f_MappingPivots = Sheets(" | ||
- | column_g_MappingPivots = Sheets(" | ||
- | | ||
- | ' Tidy up for Mapping Pivots columns. | ||
- | ' This effects binary searches, so initially in the columns if a blank is encountered then actual value | ||
- | ' is written in its place. | ||
- | prev_a = column_a_MappingPivots(LBound(column_a_MappingPivots), | ||
- | prev_b = column_b_MappingPivots(LBound(column_b_MappingPivots), | ||
- | For n = LBound(column_a_MappingPivots) To UBound(column_a_MappingPivots) | ||
- | If column_a_MappingPivots(n, | ||
- | column_a_MappingPivots(n, | ||
- | End If | ||
- | If column_b_MappingPivots(n, | ||
- | column_b_MappingPivots(n, | ||
- | End If | ||
- | prev_a = column_a_MappingPivots(n, | ||
- | prev_b = column_b_MappingPivots(n, | ||
- | Next n | ||
- | | ||
- | prev_f = column_f_MappingPivots(LBound(column_f_MappingPivots), | ||
- | prev_g = column_g_MappingPivots(LBound(column_g_MappingPivots), | ||
- | For n = LBound(column_f_MappingPivots) To UBound(column_f_MappingPivots) | ||
- | If column_f_MappingPivots(n, | ||
- | column_f_MappingPivots(n, | ||
- | End If | ||
- | If column_g_MappingPivots(n, | ||
- | column_g_MappingPivots(n, | ||
- | End If | ||
- | prev_f = column_f_MappingPivots(n, | ||
- | prev_g = column_g_MappingPivots(n, | ||
- | Next n | ||
- | | ||
- | For n = LBound(working) To UBound(working) | ||
- | |||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | If ArrayCountIf(column_a_MappingPivots, | ||
- | working(n, 1) = ArrayFind(column_a_MappingPivots, | ||
- | Else | ||
- | If ArrayCountIf(column_f_MappingPivots, | ||
- | working(n, 1) = ArrayFind(column_f_MappingPivots, | ||
- | Else | ||
- | working(n, 1) = " | ||
- | End If | ||
- | End If | ||
- | End If | ||
- | Next n | ||
- | |||
- | .Range(" | ||
- | | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | | ||
- | ' Column AE | ||
- | ' =IF(OR($X2=" | ||
- | | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_a = Range(" | ||
- | column_ab = Range(" | ||
- | column_a_MappingPivots = Sheets(" | ||
- | column_c_MappingPivots = Sheets(" | ||
- | column_f_MappingPivots = Sheets(" | ||
- | column_h_MappingPivots = Sheets(" | ||
- | | ||
- | ' Tidy up for Mapping Pivots columns. | ||
- | ' This effects binary searches, so initially in the columns if a blank is encountered then actual value | ||
- | ' is written in its place. | ||
- | prev_a = column_a_MappingPivots(LBound(column_a_MappingPivots), | ||
- | prev_c = column_c_MappingPivots(LBound(column_c_MappingPivots), | ||
- | For n = LBound(column_a_MappingPivots) To UBound(column_a_MappingPivots) | ||
- | If column_a_MappingPivots(n, | ||
- | column_a_MappingPivots(n, | ||
- | End If | ||
- | If column_c_MappingPivots(n, | ||
- | column_c_MappingPivots(n, | ||
- | End If | ||
- | prev_a = column_a_MappingPivots(n, | ||
- | prev_c = column_c_MappingPivots(n, | ||
- | Next n | ||
- | | ||
- | prev_f = column_f_MappingPivots(LBound(column_f_MappingPivots), | ||
- | prev_h = column_h_MappingPivots(LBound(column_h_MappingPivots), | ||
- | For n = LBound(column_f_MappingPivots) To UBound(column_f_MappingPivots) | ||
- | If column_f_MappingPivots(n, | ||
- | column_f_MappingPivots(n, | ||
- | End If | ||
- | If column_h_MappingPivots(n, | ||
- | column_h_MappingPivots(n, | ||
- | End If | ||
- | prev_f = column_f_MappingPivots(n, | ||
- | prev_h = column_h_MappingPivots(n, | ||
- | Next n | ||
- | |||
- | For n = LBound(working) To UBound(working) | ||
- | |||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | If ArrayCountIf(column_a_MappingPivots, | ||
- | working(n, 1) = ArrayFind(column_a_MappingPivots, | ||
- | Else | ||
- | If ArrayCountIf(column_f_MappingPivots, | ||
- | working(n, 1) = ArrayFind(column_f_MappingPivots, | ||
- | Else | ||
- | working(n, 1) = " | ||
- | End If | ||
- | End If | ||
- | End If | ||
- | Next n | ||
- | |||
- | .Range(" | ||
- | | ||
- | ' TODO Peter, this might be able to be combined with previous calc on column AC, as using same lookups. | ||
- | ' Simply use a different ' | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Column AG | ||
- | ' =IF(OR($X2=" | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_a = Range(" | ||
- | column_i = Range(" | ||
- | column_a_FinalABC = Sheets(" | ||
- | column_n_FinalABC = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | If ArrayCountIf(column_a, | ||
- | working(n, 1) = " | ||
- | Else | ||
- | working(n, 1) = Round(ArraySumIf(column_a, | ||
- | End If | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | | ||
- | ' Column AH | ||
- | ' =IF(AG2=" | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_a = Range(" | ||
- | column_i = Range(" | ||
- | column_a_FinalABC = Sheets(" | ||
- | column_n_FinalABC = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_x(n, | ||
- | 'If working(n, 1) = "NON REPORTABLE" | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | If (column_y(n, | ||
- | working(n, 1) = Round(ArraySumIf(column_a, | ||
- | | ||
- | If ((working(n, | ||
- | working(n, 1) = column_k(n, 1) | ||
- | Else | ||
- | working(n, 1) = " | ||
- | End If | ||
- | Else | ||
- | working(n, 1) = " | ||
- | End If | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Copy adjustment data. | ||
- | ' | ||
- | | ||
- | | ||
- | ' Column AJ | ||
- | ' =IF(OR($X2=" | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_e = Range(" | ||
- | column_ai = Range(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | If IsNumeric(column_ai(n, | ||
- | working(n, 1) = Round(column_e(n, | ||
- | Else | ||
- | working(n, 1) = 0 | ||
- | End If | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Column AK | ||
- | ' =IF(OR($X2=" | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_a = Range(" | ||
- | column_aj = Range(" | ||
- | column_a_FinalABC = Sheets(" | ||
- | column_n_FinalABC = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | ' | ||
- | working(n, 1) = ArraySumIf(column_a, | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | | ||
- | ' Column AL | ||
- | ' =IF(OR($X2=" | ||
- | | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_a = Range(" | ||
- | column_ab = Range(" | ||
- | column_a_MappingPivots = Sheets(" | ||
- | column_d_MappingPivots = Sheets(" | ||
- | column_f_MappingPivots = Sheets(" | ||
- | column_i_MappingPivots = Sheets(" | ||
- | | ||
- | ' Tidy up for Mapping Pivots columns. | ||
- | ' This effects binary searches, so initially in the columns if a blank is encountered then actual value | ||
- | ' is written in its place. | ||
- | prev_a = column_a_MappingPivots(LBound(column_a_MappingPivots), | ||
- | prev_d = column_d_MappingPivots(LBound(column_d_MappingPivots), | ||
- | For n = LBound(column_a_MappingPivots) To UBound(column_a_MappingPivots) | ||
- | If column_a_MappingPivots(n, | ||
- | column_a_MappingPivots(n, | ||
- | End If | ||
- | If column_d_MappingPivots(n, | ||
- | column_d_MappingPivots(n, | ||
- | End If | ||
- | prev_a = column_a_MappingPivots(n, | ||
- | prev_d = column_d_MappingPivots(n, | ||
- | Next n | ||
- | | ||
- | prev_f = column_f_MappingPivots(LBound(column_f_MappingPivots), | ||
- | prev_i = column_i_MappingPivots(LBound(column_i_MappingPivots), | ||
- | For n = LBound(column_f_MappingPivots) To UBound(column_f_MappingPivots) | ||
- | If column_f_MappingPivots(n, | ||
- | column_f_MappingPivots(n, | ||
- | End If | ||
- | If column_i_MappingPivots(n, | ||
- | column_i_MappingPivots(n, | ||
- | End If | ||
- | prev_f = column_f_MappingPivots(n, | ||
- | prev_i = column_i_MappingPivots(n, | ||
- | Next n | ||
- | |||
- | For n = LBound(working) To UBound(working) | ||
- | |||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | If ArrayCountIf(column_a_MappingPivots, | ||
- | working(n, 1) = ArrayFind(column_a_MappingPivots, | ||
- | Else | ||
- | If ArrayCountIf(column_f_MappingPivots, | ||
- | working(n, 1) = ArrayFind(column_f_MappingPivots, | ||
- | Else | ||
- | working(n, 1) = " | ||
- | End If | ||
- | End If | ||
- | End If | ||
- | Next n | ||
- | |||
- | .Range(" | ||
- | | ||
- | | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Copy adjustment data. | ||
- | ' | ||
- | | ||
- | | ||
- | ' Column AN | ||
- | ' =IF(OR($X2=" | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_a = Range(" | ||
- | column_am = Range(" | ||
- | column_k_MappingPivots = Sheets(" | ||
- | column_m_MappingPivots = Sheets(" | ||
- | |||
- | For n = LBound(working) To UBound(working) | ||
- | |||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | working(n, 1) = ArrayFind(column_k_MappingPivots, | ||
- | End If | ||
- | | ||
- | Next n | ||
- | |||
- | .Range(" | ||
- | |||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | | ||
- | ' Column AO | ||
- | ' =IF(OR($X2=" | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_f = Range(" | ||
- | column_an = Range(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | If (column_an(n, | ||
- | working(n, 1) = 0 | ||
- | Else | ||
- | working(n, 1) = column_f(n, 1) / column_an(n, | ||
- | End If | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Column AP | ||
- | ' =IF(OR($X2=" | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_a = Range(" | ||
- | column_ao = Range(" | ||
- | column_a_FinalABC = Sheets(" | ||
- | column_k_FinalABC = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | If ArrayCountIf(column_a, | ||
- | working(n, 1) = " | ||
- | Else | ||
- | working(n, 1) = Round(ArraySumIf(column_a, | ||
- | End If | ||
- | End If | ||
- | Next n | ||
- | |||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Column AQ | ||
- | ' =IF(OR($X2=" | ||
- | | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_t = Range(" | ||
- | column_r = Range(" | ||
- | column_b_Wxxxx = Sheets(" | ||
- | column_y_Wxxxx = Sheets(" | ||
- | column_z_Wxxxx = Sheets(" | ||
- | column_k = Range(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | working(n, 1) = column_t(n, 1) & " - " | ||
- | | ||
- | tmp = ArrayFind(column_b_Wxxxx, | ||
- | If tmp = " | ||
- | working(n, 1) = working(n, 1) & " | ||
- | Else | ||
- | working(n, 1) = working(n, 1) & " | ||
- | End If | ||
- | | ||
- | tmp = ArrayFind(column_b_Wxxxx, | ||
- | working(n, 1) = working(n, 1) & tmp & " - " & column_k(n, 1) | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Column AR | ||
- | ' =IF(OR($X2=" | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_aq = Range(" | ||
- | column_h_References = Sheets(" | ||
- | column_i_References = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | working(n, 1) = ArrayFind(column_h_References, | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Column AS | ||
- | ' =IF(OR($X2=" | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_aq = Range(" | ||
- | column_h_References = Sheets(" | ||
- | column_j_References = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | working(n, 1) = ArrayFind(column_h_References, | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Column AT | ||
- | ' =IF(OR($X2=" | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_aq = Range(" | ||
- | column_h_References = Sheets(" | ||
- | column_k_References = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | working(n, 1) = ArrayFind(column_h_References, | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Copy adjustment data. | ||
- | ' | ||
- | | ||
- | | ||
- | ' Column AV | ||
- | ' =IF(OR($X2=" | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_ad = Range(" | ||
- | column_af = Range(" | ||
- | column_s_References = Sheets(" | ||
- | column_u_References = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | working(n, 1) = ArrayFind(column_s_References, | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Column AW | ||
- | ' =IF(OR($X2=" | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_ar = Range(" | ||
- | column_k = Range(" | ||
- | column_au = Range(" | ||
- | column_ai = Range(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | If (column_ar(n, | ||
- | working(n, 1) = "NO ADJUSTMENT REQUIRED" | ||
- | Else | ||
- | working(n, 1) = " | ||
- | End If | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Column AX | ||
- | ' =IF(OR($X2=" | ||
- | column_x = Range(" | ||
- | column_y = Range(" | ||
- | column_r = Range(" | ||
- | column_t = Range(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_x(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | If (column_r(n, | ||
- | working(n, 1) = " | ||
- | Else | ||
- | If (column_t(n, | ||
- | working(n, 1) = " | ||
- | Else | ||
- | working(n, 1) = " | ||
- | End If | ||
- | End If | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Column AY | ||
- | ' =IF(AW2=" | ||
- | column_aw = Range(" | ||
- | column_f = Range(" | ||
- | column_au = Range(" | ||
- | column_i = Range(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_aw(n, | ||
- | working(n, 1) = "NO ADJUSTMENT REQUIRED" | ||
- | Else | ||
- | If (column_aw(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | working(n, 1) = Round((column_f(n, | ||
- | End If | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Column BB | ||
- | ' =IF(ISNA(VLOOKUP(U2, | ||
- | column_u = Range(" | ||
- | column_ag_References = Sheets(" | ||
- | column_aw = Range(" | ||
- | column_t = Range(" | ||
- | column_au = Range(" | ||
- | column_o_References = Sheets(" | ||
- | column_q_References = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If ArrayCountIf(column_ag_References, | ||
- | If column_aw(n, | ||
- | working(n, 1) = "NO ADJUSTMENT REQUIRED" | ||
- | Else | ||
- | If column_aw(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | working(n, 1) = ArrayFind(column_o_References, | ||
- | End If | ||
- | | ||
- | End If | ||
- | ' | ||
- | Else | ||
- | working(n, 1) = "NO ADJUSTMENT REQUIRED" | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Column BD | ||
- | ' =IF(AW2=" | ||
- | column_aw = Range(" | ||
- | column_au = Range(" | ||
- | column_o_References = Sheets(" | ||
- | column_p_References = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_aw(n, | ||
- | working(n, 1) = "NO ADJUSTMENT REQUIRED" | ||
- | Else | ||
- | If (column_aw(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | working(n, 1) = ArrayFind(column_o_References, | ||
- | End If | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Column BE | ||
- | ' | ||
- | column_aw = Range(" | ||
- | column_bd = Range(" | ||
- | column_m = Range(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | | ||
- | If (column_aw(n, | ||
- | working(n, 1) = "NO ADJUSTMENT REQUIRED" | ||
- | Else | ||
- | If (column_aw(n, | ||
- | working(n, 1) = "NON REPORTABLE" | ||
- | Else | ||
- | If (column_bd(n, | ||
- | working(n, 1) = " | ||
- | Else | ||
- | working(n, 1) = " | ||
- | End If | ||
- | End If | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Column BG | ||
- | ' =IF(ISNA(VLOOKUP(R2& | ||
- | column_r = Range(" | ||
- | column_n = Range(" | ||
- | column_a_HOLDINGS = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | working(n, 1) = ArrayFindEx(column_a_HOLDINGS, | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | |||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Column BH | ||
- | ' | ||
- | column_r = Range(" | ||
- | column_n = Range(" | ||
- | column_a_HOLDINGS = Sheets(" | ||
- | column_f_HOLDINGS = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | working(n, 1) = ArrayFind(column_a_HOLDINGS, | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Column BI | ||
- | ' =IF(BH2=" | ||
- | column_bh = Range(" | ||
- | column_a_References = Sheets(" | ||
- | column_b_References = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | If column_bh(n, | ||
- | working(n, 1) = "NO HOLDINGS" | ||
- | Else | ||
- | working(n, 1) = ArrayFind(column_a_References, | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Column BJ | ||
- | ' =IF(OR(BB2=" | ||
- | column_bb = Range(" | ||
- | column_y = Range(" | ||
- | column_p = Range(" | ||
- | column_h = Range(" | ||
- | column_r = Range(" | ||
- | column_a_TRANSACTIONS = Sheets(" | ||
- | column_l_TRANSACTIONS = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | If column_bb(n, | ||
- | working(n, 1) = "NO ADJUSTMENT REQUIRED" | ||
- | Else | ||
- | working(n, 1) = ArrayFind(column_a_TRANSACTIONS, | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Column BK | ||
- | ' =IF(OR(BB2=" | ||
- | column_bb = Range(" | ||
- | column_y = Range(" | ||
- | column_p = Range(" | ||
- | column_h = Range(" | ||
- | column_r = Range(" | ||
- | column_a_TRANSACTIONS = Sheets(" | ||
- | column_m_TRANSACTIONS = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | If column_bb(n, | ||
- | working(n, 1) = "NO ADJUSTMENT REQUIRED" | ||
- | Else | ||
- | working(n, 1) = ArrayFind(column_a_TRANSACTIONS, | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Column BL | ||
- | ' =IF(OR(BB2=" | ||
- | column_bb = Range(" | ||
- | column_y = Range(" | ||
- | column_p = Range(" | ||
- | column_h = Range(" | ||
- | column_r = Range(" | ||
- | column_a_TRANSACTIONS = Sheets(" | ||
- | column_n_TRANSACTIONS = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | If column_bb(n, | ||
- | working(n, 1) = "NO ADJUSTMENT REQUIRED" | ||
- | Else | ||
- | working(n, 1) = ArrayFind(column_a_TRANSACTIONS, | ||
- | End If | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Column BM | ||
- | ' =IF(ISNA(VLOOKUP(R2, | ||
- | column_r = Range(" | ||
- | column_a_QSHEET = Sheets(" | ||
- | For n = LBound(working) To UBound(working) | ||
- | working(n, 1) = ArrayFindEx(column_a_QSHEET, | ||
- | Next n | ||
- | | ||
- | .Range(" | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | End With | ||
- | End With | ||
- | |||
- | |||
- | ' Clear all objects. | ||
- | Set working = Nothing | ||
- | | ||
- | Set column_a = Nothing | ||
- | Set column_b = Nothing | ||
- | Set column_e = Nothing | ||
- | Set column_f = Nothing | ||
- | Set column_g = Nothing | ||
- | Set column_h = Nothing | ||
- | Set column_i = Nothing | ||
- | Set column_k = Nothing | ||
- | Set column_m = Nothing | ||
- | Set column_n = Nothing | ||
- | Set column_p = Nothing | ||
- | Set column_r = Nothing | ||
- | Set column_t = Nothing | ||
- | Set column_u = Nothing | ||
- | Set column_x = Nothing | ||
- | Set column_y = Nothing | ||
- | Set column_ab = Nothing | ||
- | Set column_ad = Nothing | ||
- | Set column_af = Nothing | ||
- | Set column_ai = Nothing | ||
- | Set column_aj = Nothing | ||
- | Set column_an = Nothing | ||
- | Set column_ao = Nothing | ||
- | Set column_aq = Nothing | ||
- | Set column_ar = Nothing | ||
- | Set column_au = Nothing | ||
- | Set column_aw = Nothing | ||
- | Set column_bb = Nothing | ||
- | Set column_bd = Nothing | ||
- | Set column_bh = Nothing | ||
- | | ||
- | Set column_a_CUST = Nothing | ||
- | Set column_b_CUST = Nothing | ||
- | Set column_a_FinalABC = Nothing | ||
- | Set column_d_FinalABC = Nothing | ||
- | Set column_k_FinalABC = Nothing | ||
- | Set column_n_FinalABC = Nothing | ||
- | Set column_a_HOLDINGS = Nothing | ||
- | Set column_f_HOLDINGS = Nothing | ||
- | Set column_a_MappingPivots = Nothing | ||
- | Set column_b_MappingPivots = Nothing | ||
- | Set column_c_MappingPivots = Nothing | ||
- | Set column_f_MappingPivots = Nothing | ||
- | Set column_g_MappingPivots = Nothing | ||
- | Set column_h_MappingPivots = Nothing | ||
- | Set column_a_References = Nothing | ||
- | Set column_b_References = Nothing | ||
- | Set column_h_References = Nothing | ||
- | Set column_k_References = Nothing | ||
- | Set column_s_References = Nothing | ||
- | Set column_u_References = Nothing | ||
- | Set column_ag_References = Nothing | ||
- | Set column_a_QSHEET = Nothing | ||
- | Set column_a_TRANSACTIONS = Nothing | ||
- | Set column_l_TRANSACTIONS = Nothing | ||
- | Set column_m_TRANSACTIONS = Nothing | ||
- | Set column_n_TRANSACTIONS = Nothing | ||
- | Set column_b_Wxxxx = Nothing | ||
- | Set column_y_Wxxxx = Nothing | ||
- | Set column_z_Wxxxx = Nothing | ||
- | | ||
- | Set prev_a = Nothing | ||
- | Set prev_b = Nothing | ||
- | Set prev_c = Nothing | ||
- | Set prev_f = Nothing | ||
- | Set prev_g = Nothing | ||
- | Set prev_h = Nothing | ||
- | | ||
- | Set tmp = Nothing | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Copies remaining formulae down on the SHEETNAME1 sheet. | ||
- | Sub M10625_Recalc_SHEETNAME1_Formulae() | ||
- | |||
- | Dim lastrow_SHEETNAME1 As Long | ||
- | Dim lastrow_FinalABC As Long | ||
- | Dim top_row As Integer | ||
- | Dim source As String | ||
- | Dim SHEETNAME1_range As Range | ||
- | Dim FinalABC_range As Range | ||
- | | ||
- | |||
- | ' Set top row for pivots. | ||
- | ' top_row is row in which pivots at the top are created. | ||
- | top_row = 5 | ||
- | |||
- | |||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | | ||
- | | ||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | ' | ||
- | On Error Resume Next | ||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | | ||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | ' | ||
- | lastrow_SHEETNAME1 = .Sheets(" | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_SHEETNAME1 < 3 Then | ||
- | lastrow_SHEETNAME1 = 3 | ||
- | End If | ||
- | |||
- | | ||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | ' | ||
- | lastrow_FinalABC = .Sheets(" | ||
- | | ||
- | Set SHEETNAME1_range = Range(" | ||
- | Set FinalABC_range = Range(" | ||
- | | ||
- | | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | |||
- | |||
- | ' Select A1. | ||
- | ScrollTo ActiveSheet.name, | ||
- | |||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Copy adjustment data. | ||
- | ' | ||
- | | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Copy adjustment data. | ||
- | ' | ||
- | | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Copy adjustment data. | ||
- | ' | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Depends on the earlier pivots. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Copy adjustment data. | ||
- | ' | ||
- | | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | |||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Copy adjustment data. | ||
- | ' | ||
- | | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | End With | ||
- | End With | ||
- | |||
- | |||
- | ' Clear all objects. | ||
- | Set SHEETNAME1_range = Nothing | ||
- | Set FinalABC_range = Nothing | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Format the FinalABC sheet to put lines between ISINs. | ||
- | Sub M10700_Format_FinalABC_lines() | ||
- | |||
- | Dim myISIN_Change As Variant | ||
- | Dim lastrow_FinalABC As Long | ||
- | |||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | | ||
- | | ||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | | ||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | ' | ||
- | lastrow_FinalABC = .Sheets(" | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_FinalABC < 3 Then | ||
- | lastrow_FinalABC = 3 | ||
- | End If | ||
- | |||
- | |||
- | |||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Calculate first to ensure that we know when there is a change to the ISIN. | ||
- | ' | ||
- | ' | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | |||
- | |||
- | |||
- | ' | ||
- | For Each myISIN_Change In .Range(" | ||
- | If myISIN_Change = False Then | ||
- | .Range(" | ||
- | With Selection.Borders(xlEdgeTop) | ||
- | .LineStyle = xlDouble | ||
- | .Color = -4165632 | ||
- | .TintAndShade = 0 | ||
- | .Weight = xlThick | ||
- | End With | ||
- | End If | ||
- | Next myISIN_Change | ||
- | End With | ||
- | End With | ||
- | | ||
- | | ||
- | ' Clear all objects. | ||
- | Set myISIN_Change = Nothing | ||
- | | ||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Format the SHEETNAME1 sheet by placing lines between ISINs. | ||
- | Sub M10710_Format_SHEETNAME1_Lines() | ||
- | |||
- | Dim lastrow_SHEETNAME1 As Long | ||
- | Dim myISIN_Change As Variant | ||
- | |||
- | |||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | | ||
- | | ||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | | ||
- | | ||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_SHEETNAME1 = .Sheets(" | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_SHEETNAME1 < 3 Then | ||
- | lastrow_SHEETNAME1 = 3 | ||
- | End If | ||
- | | ||
- | | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | |||
- | |||
- | ' Application.Calculate | ||
- | ' | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | |||
- | |||
- | ' | ||
- | For Each myISIN_Change In .Range(" | ||
- | If myISIN_Change = False Then | ||
- | .Range(" | ||
- | With Selection.Borders(xlEdgeTop) | ||
- | .LineStyle = xlDouble | ||
- | .Color = -4165632 | ||
- | .TintAndShade = 0 | ||
- | .Weight = xlThick | ||
- | End With | ||
- | End If | ||
- | Next myISIN_Change | ||
- | End With | ||
- | End With | ||
- | |||
- | | ||
- | ' Clear all objects. | ||
- | Set myISIN_Change = Nothing | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Refresh the PIVOT tables on the REC DASHBOARD sheet. | ||
- | Sub M10800_Refresh_Rec_Dashboard_Pivots() | ||
- | |||
- | Dim lastrow_SHEETNAME1 As Long | ||
- | Dim lastrow_FinalABC As Long | ||
- | |||
- | Dim pc As PivotCache | ||
- | Dim pt As PivotTable | ||
- | |||
- | Dim top_row As Integer | ||
- | Dim bottom_row As Integer | ||
- | |||
- | |||
- | ' Set top and bottom row for pivots. | ||
- | ' top_row is row in which pivots at the top are created. | ||
- | ' bottom_row is row in which pivots below are created. | ||
- | top_row = 5 | ||
- | bottom_row = 20 | ||
- | |||
- | |||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | | ||
- | | ||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | | ||
- | ' Stop alerts about replacing contents of cells. | ||
- | Application.DisplayAlerts = False | ||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | |||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | ' | ||
- | lastrow_FinalABC = .Sheets(" | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_FinalABC < 3 Then | ||
- | lastrow_FinalABC = 3 | ||
- | End If | ||
- | |||
- | | ||
- | lastrow_SHEETNAME1 = .Sheets(" | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_SHEETNAME1 < 3 Then | ||
- | lastrow_SHEETNAME1 = 3 | ||
- | End If | ||
- | |||
- | |||
- | With Sheets(" | ||
- | |||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | |||
- | |||
- | ' Delete all existing Pivot Tables in the worksheet. | ||
- | ' In the TableRange1 property, page fields are excluded; | ||
- | ' To select the entire PivotTable report, including the page fields, use the TableRange2 property. | ||
- | For Each pt In .PivotTables | ||
- | pt.TableRange2.Clear | ||
- | Next pt | ||
- | |||
- | |||
- | ' | ||
- | |||
- | ' Creating Pivot cache. | ||
- | Set pc = ActiveWorkbook.PivotCaches.Create(xlDatabase, | ||
- | |||
- | | ||
- | ' Creating Pivot table. | ||
- | Set pt = pc.CreatePivotTable(.Range(" | ||
- | |||
- | |||
- | ' Set the Pivot fields to display. | ||
- | With pt | ||
- | ' Turn off automatic updation of Pivot Table during the process of its creation to speed up code. | ||
- | .ManualUpdate = True | ||
- | |||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Set row field. | ||
- | With .PivotFields(" | ||
- | 'pvi = .PivotItems(" | ||
- | ' | ||
- | .Orientation = xlRowField | ||
- | .Position = 1 | ||
- | End With | ||
- | |||
- | | ||
- | ' Set column field. | ||
- | 'With .PivotFields(" | ||
- | ' | ||
- | ' | ||
- | 'End With | ||
- | |||
- | | ||
- | ' Set data field. | ||
- | ' | ||
- | | ||
- | | ||
- | ' Set data field. | ||
- | With .PivotFields(" | ||
- | .Orientation = xlDataField | ||
- | .Function = xlSum | ||
- | .NumberFormat = "#,## | ||
- | .Position = 1 | ||
- | End With | ||
- | | ||
- | | ||
- | ' Turn on automatic update / calculation in the Pivot Table. | ||
- | .ManualUpdate = False | ||
- | | ||
- | | ||
- | ' Get the actual data. | ||
- | .RefreshTable | ||
- | | ||
- | | ||
- | ' Make the Grand Total yellow. | ||
- | .PivotSelect name: | ||
- | Selection.Interior.Color = vbYellow | ||
- | | ||
- | End With | ||
- | |||
- | |||
- | |||
- | ' | ||
- | |||
- | ' Creating Pivot cache. | ||
- | Set pc = ActiveWorkbook.PivotCaches.Create(xlDatabase, | ||
- | |||
- | |||
- | ' Creating Pivot table. | ||
- | 'Set pt = pc.CreatePivotTable(ws.Range(" | ||
- | Set pt = pc.CreatePivotTable(.Range(" | ||
- | |||
- | |||
- | ' Set the Pivot fields to display. | ||
- | With pt | ||
- | ' Turn off automatic updation of Pivot Table during the process of its creation to speed up code. | ||
- | .ManualUpdate = True | ||
- | |||
- | |||
- | ' Set row field. | ||
- | With .PivotFields(" | ||
- | ' | ||
- | .Orientation = xlRowField | ||
- | .Position = 1 | ||
- | End With | ||
- | |||
- | | ||
- | ' Set data field. | ||
- | With .PivotFields(" | ||
- | .Orientation = xlDataField | ||
- | .Function = xlSum | ||
- | .NumberFormat = "#,## | ||
- | .Position = 1 | ||
- | End With | ||
- | | ||
- | | ||
- | ' Turn on automatic update / calculation in the Pivot Table. | ||
- | .ManualUpdate = False | ||
- | |||
- | | ||
- | ' Get the actual data. | ||
- | .RefreshTable | ||
- | | ||
- | | ||
- | ' Make the Grand Total yellow. | ||
- | .PivotSelect name: | ||
- | Selection.Interior.Color = vbYellow | ||
- | |||
- | End With | ||
- | |||
- | |||
- | |||
- | ' | ||
- | |||
- | ' Creating Pivot cache. | ||
- | Set pc = ActiveWorkbook.PivotCaches.Create(xlDatabase, | ||
- | |||
- | |||
- | ' Creating Pivot table. | ||
- | Set pt = pc.CreatePivotTable(.Range(" | ||
- | |||
- | |||
- | ' Set the Pivot fields to display. | ||
- | With pt | ||
- | ' Set tabular form for entire pivot table. | ||
- | ' | ||
- | |||
- | |||
- | ' Turn off automatic updation of Pivot Table during the process of its creation to speed up code. | ||
- | .ManualUpdate = True | ||
- | |||
- | |||
- | ' Set row field. | ||
- | With .PivotFields(" | ||
- | .Orientation = xlRowField | ||
- | .Position = 1 | ||
- | .Subtotals = Array(False, | ||
- | .LayoutForm = xlTabular | ||
- | End With | ||
- | |||
- | With .PivotFields(" | ||
- | .Orientation = xlRowField | ||
- | .Position = 2 | ||
- | .Subtotals = Array(False, | ||
- | .LayoutForm = xlTabular | ||
- | End With | ||
- | |||
- | | ||
- | ' Set data field. | ||
- | With .PivotFields(" | ||
- | .Orientation = xlDataField | ||
- | .Function = xlSum | ||
- | .NumberFormat = "#,## | ||
- | .Position = 1 | ||
- | End With | ||
- | | ||
- | | ||
- | ' Turn on automatic update / calculation in the Pivot Table. | ||
- | .ManualUpdate = False | ||
- | |||
- | |||
- | ' Get the actual data. | ||
- | .RefreshTable | ||
- | | ||
- | | ||
- | ' Make the Grand Total yellow. | ||
- | .PivotSelect name: | ||
- | Selection.Interior.Color = vbYellow | ||
- | | ||
- | End With | ||
- | |||
- | |||
- | ' | ||
- | |||
- | ' Creating Pivot cache. | ||
- | Set pc = ActiveWorkbook.PivotCaches.Create(xlDatabase, | ||
- | |||
- | |||
- | ' Creating Pivot table. | ||
- | 'Set pt = pc.CreatePivotTable(ws.Range(" | ||
- | Set pt = pc.CreatePivotTable(.Range(" | ||
- | |||
- | |||
- | ' Set the Pivot fields to display. | ||
- | With pt | ||
- | ' Turn off automatic updation of Pivot Table during the process of its creation to speed up code. | ||
- | .ManualUpdate = True | ||
- | |||
- | | ||
- | ' Set row field. | ||
- | With .PivotFields(" | ||
- | .Orientation = xlRowField | ||
- | .Position = 1 | ||
- | .Subtotals = Array(False, | ||
- | .LayoutForm = xlTabular | ||
- | End With | ||
- | | ||
- | With .PivotFields(" | ||
- | .Orientation = xlRowField | ||
- | .Position = 2 | ||
- | .Subtotals = Array(False, | ||
- | .LayoutForm = xlTabular | ||
- | End With | ||
- | |||
- | | ||
- | ' Set data field. | ||
- | With .PivotFields(" | ||
- | .Orientation = xlDataField | ||
- | .Function = xlSum | ||
- | .NumberFormat = "#,## | ||
- | .Position = 1 | ||
- | End With | ||
- | | ||
- | | ||
- | ' Turn on automatic update / calculation in the Pivot Table. | ||
- | .ManualUpdate = False | ||
- | | ||
- | | ||
- | ' Get the actual data. | ||
- | .RefreshTable | ||
- | | ||
- | | ||
- | ' Make the Grand Total yellow. | ||
- | .PivotSelect name: | ||
- | Selection.Interior.Color = vbYellow | ||
- | | ||
- | End With | ||
- | |||
- | |||
- | |||
- | ' | ||
- | |||
- | ' Creating Pivot cache. | ||
- | Set pc = ActiveWorkbook.PivotCaches.Create(xlDatabase, | ||
- | |||
- | |||
- | ' Creating Pivot table. | ||
- | Set pt = pc.CreatePivotTable(.Range(" | ||
- | |||
- | |||
- | ' Set the Pivot fields to display. | ||
- | With pt | ||
- | ' Set tabular form for entire pivot table. | ||
- | ' | ||
- | |||
- | | ||
- | ' Turn off automatic updation of Pivot Table during the process of its creation to speed up code. | ||
- | .ManualUpdate = True | ||
- | |||
- | | ||
- | ' Set row field. | ||
- | With .PivotFields(" | ||
- | .Orientation = xlRowField | ||
- | .Position = 1 | ||
- | .Subtotals = Array(False, | ||
- | .LayoutForm = xlTabular | ||
- | End With | ||
- | |||
- | | ||
- | ' Set data field. | ||
- | With .PivotFields(" | ||
- | .Orientation = xlDataField | ||
- | .Function = xlSum | ||
- | .NumberFormat = "#,## | ||
- | .Position = 1 | ||
- | End With | ||
- | | ||
- | | ||
- | ' Turn on automatic update / calculation in the Pivot Table. | ||
- | .ManualUpdate = False | ||
- | |||
- | | ||
- | ' Get the actual data. | ||
- | .RefreshTable | ||
- | | ||
- | | ||
- | ' Make the Grand Total yellow. | ||
- | .PivotSelect name: | ||
- | Selection.Interior.Color = vbYellow | ||
- | |||
- | End With | ||
- | |||
- | |||
- | ' | ||
- | |||
- | ' Creating Pivot cache. | ||
- | Set pc = ActiveWorkbook.PivotCaches.Create(xlDatabase, | ||
- | |||
- | |||
- | ' Creating Pivot table. | ||
- | 'Set pt = pc.CreatePivotTable(ws.Range(" | ||
- | Set pt = pc.CreatePivotTable(.Range(" | ||
- | |||
- | |||
- | ' Set the Pivot fields to display. | ||
- | With pt | ||
- | ' Turn off automatic updation of Pivot Table during the process of its creation to speed up code. | ||
- | .ManualUpdate = True | ||
- | |||
- | | ||
- | ' Set row field. | ||
- | With .PivotFields(" | ||
- | .Orientation = xlRowField | ||
- | .Position = 1 | ||
- | .Subtotals = Array(False, | ||
- | .LayoutForm = xlTabular | ||
- | End With | ||
- | | ||
- | | ||
- | ' Set data field. | ||
- | With .PivotFields(" | ||
- | .Orientation = xlDataField | ||
- | .Function = xlSum | ||
- | .NumberFormat = "#,## | ||
- | .Position = 1 | ||
- | End With | ||
- | | ||
- | | ||
- | ' Turn on automatic update / calculation in the Pivot Table. | ||
- | .ManualUpdate = False | ||
- | |||
- | | ||
- | ' Get the actual data. | ||
- | .RefreshTable | ||
- | | ||
- | | ||
- | ' Make the Grand Total yellow. | ||
- | .PivotSelect name: | ||
- | Selection.Interior.Color = vbYellow | ||
- | |||
- | End With | ||
- | |||
- | |||
- | |||
- | |||
- | ' | ||
- | |||
- | ' Creating Pivot cache. | ||
- | Set pc = ActiveWorkbook.PivotCaches.Create(xlDatabase, | ||
- | |||
- | |||
- | ' Creating Pivot table. | ||
- | 'Set pt = pc.CreatePivotTable(ws.Range(" | ||
- | Set pt = pc.CreatePivotTable(.Range(" | ||
- | |||
- | |||
- | ' Set the Pivot fields to display. | ||
- | With pt | ||
- | ' Turn off automatic updation of Pivot Table during the process of its creation to speed up code. | ||
- | .ManualUpdate = True | ||
- | |||
- | | ||
- | ' Set row field. | ||
- | With .PivotFields(" | ||
- | .Orientation = xlRowField | ||
- | .Position = 1 | ||
- | ' | ||
- | 'set Index 1 (Automatic) to True which sets all other values to False: | ||
- | .Subtotals(1) = True | ||
- | .LayoutForm = xlTabular | ||
- | End With | ||
- | | ||
- | With .PivotFields(" | ||
- | .Orientation = xlRowField | ||
- | .Position = 2 | ||
- | .Subtotals = Array(False, | ||
- | .LayoutForm = xlTabular | ||
- | End With | ||
- | | ||
- | With .PivotFields(" | ||
- | .Orientation = xlRowField | ||
- | .Position = 3 | ||
- | .Subtotals = Array(False, | ||
- | .LayoutForm = xlTabular | ||
- | End With | ||
- | | ||
- | With .PivotFields(" | ||
- | .Orientation = xlRowField | ||
- | .Position = 4 | ||
- | .Subtotals = Array(False, | ||
- | .LayoutForm = xlTabular | ||
- | End With | ||
- | | ||
- | | ||
- | ' Set data field. | ||
- | With .PivotFields(" | ||
- | .Orientation = xlDataField | ||
- | .Function = xlSum | ||
- | .NumberFormat = "#,## | ||
- | .Position = 1 | ||
- | End With | ||
- | | ||
- | | ||
- | ' Turn on automatic update / calculation in the Pivot Table. | ||
- | .ManualUpdate = False | ||
- | |||
- | | ||
- | ' Get the actual data. | ||
- | .RefreshTable | ||
- | | ||
- | | ||
- | ' Make the Grand Total yellow. | ||
- | .PivotSelect name: | ||
- | Selection.Interior.Color = vbYellow | ||
- | | ||
- | | ||
- | ' Make QI Entity headings green | ||
- | .PivotSelect "QI Entity[All]", | ||
- | Selection.Interior.Color = RGB(204, 255, 204) | ||
- | | ||
- | | ||
- | ' Make QI Entity Sub totals yellow. | ||
- | .PivotSelect "QI Entity[All; | ||
- | Selection.Interior.Color = RGB(255, 255, 153) | ||
- | End With | ||
- | |||
- | |||
- | |||
- | ' ***** END PIVOT CREATION **** END PIVOT CREATION *** | ||
- | |||
- | ' Refresh the pivot tables. | ||
- | For Each pt In .PivotTables | ||
- | pt.RefreshTable | ||
- | pt.Update | ||
- | Next | ||
- | |||
- | |||
- | ' Put text to display on the sheet. | ||
- | ' Some text was overwritten by the pivot creation. | ||
- | ' Other text is to replace the "Row Labels" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Select A1. | ||
- | ScrollTo ActiveSheet.name, | ||
- | | ||
- | End With | ||
- | End With | ||
- | | ||
- | | ||
- | ' Clear all objects. | ||
- | Set pt = Nothing | ||
- | Set pc = Nothing | ||
- | | ||
- | End Sub | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | ' Refresh the PIVOT tables on the ADJ DASHBOARD sheet. | ||
- | Sub M10810_Refresh_Adj_Dashboard_Pivots() | ||
- | |||
- | Dim lastrow_SHEETNAME1 As Long | ||
- | |||
- | Dim pc As PivotCache | ||
- | Dim pt As PivotTable | ||
- | |||
- | Dim top_row As Integer | ||
- | Dim bottom_row As Integer | ||
- | |||
- | | ||
- | ' Set top and bottom row for pivots. | ||
- | ' top_row is row in which pivots at the top are created. | ||
- | ' bottom_row is row in which pivots below are created. | ||
- | top_row = 5 | ||
- | bottom_row = 20 | ||
- | |||
- | |||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | | ||
- | | ||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | ' Stop alerts about replacing contents of cells. | ||
- | Application.DisplayAlerts = False | ||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | | ||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_SHEETNAME1 = .Sheets(" | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_SHEETNAME1 < 3 Then | ||
- | lastrow_SHEETNAME1 = 3 | ||
- | End If | ||
- | |||
- | | ||
- | With Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | |||
- | |||
- | ' Delete all existing Pivot Tables in the worksheet. | ||
- | ' In the TableRange1 property, page fields are excluded; | ||
- | ' To select the entire PivotTable report, including the page fields, use the TableRange2 property. | ||
- | For Each pt In .PivotTables | ||
- | pt.TableRange2.Clear | ||
- | Next pt | ||
- | |||
- | |||
- | ' | ||
- | |||
- | ' Creating Pivot cache. | ||
- | Set pc = ActiveWorkbook.PivotCaches.Create(xlDatabase, | ||
- | |||
- | |||
- | ' Creating Pivot table. | ||
- | 'Set pt = pc.CreatePivotTable(ws.Range(" | ||
- | Set pt = pc.CreatePivotTable(.Range(" | ||
- | |||
- | |||
- | ' Set the Pivot fields to display. | ||
- | With pt | ||
- | ' Turn off automatic updation of Pivot Table during the process of its creation to speed up code. | ||
- | .ManualUpdate = True | ||
- | |||
- | | ||
- | ' Set row field. | ||
- | With .PivotFields(" | ||
- | .Orientation = xlRowField | ||
- | .Position = 1 | ||
- | .Subtotals = Array(False, | ||
- | .LayoutForm = xlTabular | ||
- | End With | ||
- | |||
- | With .PivotFields(" | ||
- | .Orientation = xlRowField | ||
- | .Position = 2 | ||
- | .Subtotals = Array(False, | ||
- | .LayoutForm = xlTabular | ||
- | End With | ||
- | |||
- | | ||
- | ' Set column field. | ||
- | 'With .PivotFields(" | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | 'End With | ||
- | |||
- | 'With .PivotFields(" | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | 'End With | ||
- | |||
- | |||
- | |||
- | ' Set data field. | ||
- | With .PivotFields(" | ||
- | .Orientation = xlDataField | ||
- | .Function = xlSum | ||
- | .NumberFormat = "#,## | ||
- | .Position = 1 | ||
- | End With | ||
- | | ||
- | | ||
- | 'With .PivotFields(" | ||
- | With .PivotFields(" | ||
- | .Orientation = xlDataField | ||
- | .Function = xlCount | ||
- | .NumberFormat = "#,## | ||
- | .Position = 2 | ||
- | End With | ||
- | | ||
- | | ||
- | ' Turn on automatic update / calculation in the Pivot Table. | ||
- | .ManualUpdate = False | ||
- | |||
- | | ||
- | ' Get the actual data. | ||
- | .RefreshTable | ||
- | | ||
- | |||
- | ' Make BBH Income Type headings green | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Make the Grand Total yellow. | ||
- | .PivotSelect name: | ||
- | Selection.Interior.Color = vbYellow | ||
- | | ||
- | End With | ||
- | |||
- | |||
- | |||
- | ' ***** END PIVOT CREATION **** END PIVOT CREATION *** | ||
- | |||
- | |||
- | ' Refresh the pivot tables. | ||
- | For Each pt In .PivotTables | ||
- | pt.RefreshTable | ||
- | pt.Update | ||
- | Next | ||
- | |||
- | |||
- | ' Put text to display on the sheet. | ||
- | ' Some text was overwritten by the pivot creation. | ||
- | ' Other text is to replace the "Row Labels" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Select A1. | ||
- | ScrollTo ActiveSheet.name, | ||
- | | ||
- | End With | ||
- | End With | ||
- | |||
- | |||
- | ' Clear all objects. | ||
- | Set pt = Nothing | ||
- | Set pc = Nothing | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Reverts the Corrected Date, column E, in the FinalABC sheet back to its original calculated date. | ||
- | ' It only does this for cells where column AJ does not still reconciles, i.e. does not show " | ||
- | ' This requires the following columns to have formulae throughout: | ||
- | Sub M10910_Revert_Reformatted_FinalABC_Corrected_Dates() | ||
- | |||
- | Dim lastrow_FinalABC As Long | ||
- | |||
- | | ||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | | ||
- | | ||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | |||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | |||
- | |||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | ' | ||
- | lastrow_FinalABC = .Cells(Rows.Count, | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_FinalABC < 3 Then | ||
- | lastrow_FinalABC = 3 | ||
- | End If | ||
- | |||
- | |||
- | ' Change for formula in column E to add 1 to the date. | ||
- | ' This should make dates that are the last day of the month now reflect the 1st of the following month. | ||
- | .Range(" | ||
- | |||
- | |||
- | ' Copies formulae down. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | |||
- | |||
- | ' Calculations. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | |||
- | |||
- | ' Now copy and paste formula ranges as values to speed up the file processing. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | End With | ||
- | End With | ||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Clears formatting on the SHEETNAME1 sheet. | ||
- | Sub M11000_Clear_SHEETNAME1_lines() | ||
- | |||
- | Dim lastrow_SHEETNAME1 As Long | ||
- | |||
- | |||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | | ||
- | | ||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | |||
- | |||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_SHEETNAME1 = .Cells(Rows.Count, | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_SHEETNAME1 < 3 Then | ||
- | lastrow_SHEETNAME1 = 3 | ||
- | End If | ||
- | |||
- | |||
- | ' Clear any double lines. | ||
- | .Range(" | ||
- | End With | ||
- | End With | ||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Clears formatting on the FinalABC sheet. | ||
- | Sub M11110_Clear_FinalABC_lines() | ||
- | |||
- | Dim lastrow_FinalABC As Long | ||
- | |||
- | |||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | | ||
- | | ||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | |||
- | |||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_FinalABC = .Cells(Rows.Count, | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_FinalABC < 3 Then | ||
- | lastrow_FinalABC = 3 | ||
- | End If | ||
- | |||
- | |||
- | ' Clear any double lines. | ||
- | .Range(" | ||
- | End With | ||
- | End With | ||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' For any row that has adjusted values different than the original value it recalculates the values against that row. | ||
- | ' It does this by putting formulae back in only for the specific row and then performing the recalc. | ||
- | ' Later the formula are replaced by values again. | ||
- | Sub M11200_Recalc_changed_adjusted_rows_Array() | ||
- | |||
- | Dim lastrow_SHEETNAME1 As Long | ||
- | Dim lastrow_FinalABC As Long | ||
- | |||
- | Dim recalc As Boolean | ||
- | Dim recalc_row As Boolean | ||
- | |||
- | Dim FinalABC_ISIN As String | ||
- | Dim SHEETNAME1_ISIN As String | ||
- | Dim rng As Range | ||
- | Dim var As Variant | ||
- | |||
- | Dim i As Long | ||
- | Dim J As Long | ||
- | |||
- | Dim tmpMonth1 As String | ||
- | Dim tmpMonth2 As String | ||
- | |||
- | Dim pt As PivotTable | ||
- | | ||
- | Dim column_k As Variant | ||
- | Dim column_y As Variant | ||
- | Dim column_ac As Variant | ||
- | Dim column_ad As Variant | ||
- | Dim column_ae As Variant | ||
- | Dim column_af As Variant | ||
- | Dim column_ah As Variant | ||
- | Dim column_ai As Variant | ||
- | Dim column_al As Variant | ||
- | Dim column_am As Variant | ||
- | Dim column_at As Variant | ||
- | Dim column_au As Variant | ||
- | |||
- | Dim working As Variant | ||
- | | ||
- | | ||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | | ||
- | | ||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | | ||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_SHEETNAME1 = .Sheets(" | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_SHEETNAME1 < 3 Then | ||
- | lastrow_SHEETNAME1 = 3 | ||
- | End If | ||
- | | ||
- | lastrow_FinalABC = .Sheets(" | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_FinalABC < 3 Then | ||
- | lastrow_FinalABC = 3 | ||
- | End If | ||
- | | ||
- | | ||
- | ' Loop through every row in SHEETNAME1 and check if any adjusted cell differs from the original. | ||
- | ' If so then continues with the recalc. | ||
- | recalc = False | ||
- | | ||
- | | ||
- | ReDim working(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_k(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_y(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_ac(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_ad(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_ae(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_af(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_ah(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_ai(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_al(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_am(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_at(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_au(1 To lastrow_SHEETNAME1, | ||
- | | ||
- | |||
- | ' Check SHEETNAME1 for changes. | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Load working with dummy values - just to set its size. | ||
- | working = .Range(" | ||
- | | ||
- | | ||
- | ' Load SHEETNAME1 columns into array variables. | ||
- | column_k = .Range(" | ||
- | column_y = .Range(" | ||
- | column_ac = .Range(" | ||
- | column_ad = .Range(" | ||
- | column_ae = .Range(" | ||
- | column_af = .Range(" | ||
- | column_ah = .Range(" | ||
- | column_ai = .Range(" | ||
- | column_al = .Range(" | ||
- | column_am = .Range(" | ||
- | column_at = .Range(" | ||
- | column_au = .Range(" | ||
- | | ||
- | For i = LBound(working) To UBound(working) | ||
- | | ||
- | ' If row 1, heading, skip | ||
- | If i = 1 Then | ||
- | GoTo NextIteration ' next i | ||
- | End If | ||
- | | ||
- | | ||
- | ' Default to false | ||
- | recalc_row = False | ||
- | | ||
- | | ||
- | ' Tax rate adjusted. | ||
- | If column_k(i, 1) <> "" | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' Include / Exclude. | ||
- | If column_y(i, 1) <> " | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' Income Code Adjusted. | ||
- | If column_ad(i, | ||
- | If column_ad(i, | ||
- | recalc_row = True | ||
- | End If | ||
- | End If | ||
- | | ||
- | | ||
- | ' Exemption Code Adjusted. | ||
- | If column_af(i, | ||
- | If column_af(i, | ||
- | recalc_row = True | ||
- | End If | ||
- | End If | ||
- | | ||
- | | ||
- | ' BBH Rate Adjusted. | ||
- | If column_ai(i, | ||
- | If column_ai(i, | ||
- | recalc_row = True | ||
- | End If | ||
- | End If | ||
- | | ||
- | | ||
- | ' BBH CCY Adjusted. | ||
- | If column_am(i, | ||
- | If column_am(i, | ||
- | recalc_row = True | ||
- | End If | ||
- | End If | ||
- | | ||
- | | ||
- | ' Suggested Rate Adjusted. | ||
- | If column_au(i, | ||
- | If column_au(i, | ||
- | recalc_row = True | ||
- | End If | ||
- | End If | ||
- | | ||
- | | ||
- | ' Check if recalc_row is true. | ||
- | If recalc_row = True Then | ||
- | ' Set recalc to true | ||
- | recalc = True | ||
- | | ||
- | | ||
- | ' Convert all formula cells in the row back to formulae. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | ' Recalculate the entire row. | ||
- | .Range(" | ||
- | End If | ||
- | | ||
- | | ||
- | ' TODO - Add in here loop for all affected lines in FinalABC sheet with same ISIN. | ||
- | ' Then we can remove the below copy all BBH formulae down. | ||
- | | ||
- | | ||
- | NextIteration: | ||
- | |||
- | Next i | ||
- | End With | ||
- | |||
- | |||
- | If recalc = True Then | ||
- | | ||
- | ' Refresh all impacted formula on the FinalABC sheet. | ||
- | With Sheets(" | ||
- | | ||
- | ' Activate the FinalABC sheet. | ||
- | .Activate | ||
- | |||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Recalculate the entire row. | ||
- | ' | ||
- | | ||
- | End With | ||
- | |||
- | | ||
- | ' Recalculate all worksheets. | ||
- | Application.Calculate | ||
- | | ||
- | | ||
- | ' Do refresh of pivots. | ||
- | With Sheets(" | ||
- | | ||
- | ' Activate the Mapping Pivots sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Refresh the pivot tables. | ||
- | For Each pt In .PivotTables | ||
- | pt.RefreshTable | ||
- | pt.Update | ||
- | Next | ||
- | | ||
- | End With | ||
- | | ||
- | | ||
- | ' Recalculate all worksheets again to pick up Pivot values. | ||
- | Application.Calculate | ||
- | | ||
- | | ||
- | ' Now convert all impacted formulae back to values. | ||
- | 'TODO. loop through SHEETNAME1 as above and change formulae to values for any row impacted. | ||
- | | ||
- | | ||
- | ' Convert all formulae on the FinalABC sheet to values. | ||
- | With Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | End With | ||
- | | ||
- | End If | ||
- | | ||
- | | ||
- | ' Convert all formulae on the SHEETNAME1 sheet to values. | ||
- | ' Loop through every row in SHEETNAME1 and check if any adjusted cell differs from the original. | ||
- | ' If so then continues with the changing of the formula back to values. | ||
- | recalc = False | ||
- | | ||
- | |||
- | ' Check SHEETNAME1 for changes. | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | ' Load working with dummy values - just to set its size. | ||
- | working = Range(" | ||
- | | ||
- | | ||
- | ' Load SHEETNAME1 columns into array variables. | ||
- | column_k = .Range(" | ||
- | column_y = .Range(" | ||
- | column_ac = .Range(" | ||
- | column_ad = .Range(" | ||
- | column_ae = .Range(" | ||
- | column_af = .Range(" | ||
- | column_ah = .Range(" | ||
- | column_ai = .Range(" | ||
- | column_al = .Range(" | ||
- | column_am = .Range(" | ||
- | column_at = .Range(" | ||
- | column_au = .Range(" | ||
- | | ||
- | For i = LBound(working) To UBound(working) | ||
- | |||
- | ' If row 1, heading, skip | ||
- | If i = 1 Then | ||
- | GoTo NextIteration2 ' next i | ||
- | End If | ||
- | |||
- | |||
- | ' Default to false | ||
- | recalc_row = False | ||
- | | ||
- | | ||
- | ' Tax rate adjusted. | ||
- | If column_k(i, 1) <> "" | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' Include / Exclude. | ||
- | If column_y(i, 1) <> " | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' Income Code Adjusted. | ||
- | If column_ad(i, | ||
- | If column_ad(i, | ||
- | recalc_row = True | ||
- | End If | ||
- | End If | ||
- | | ||
- | | ||
- | ' Exemption Code Adjusted. | ||
- | If column_af(i, | ||
- | If column_af(i, | ||
- | recalc_row = True | ||
- | End If | ||
- | End If | ||
- | | ||
- | | ||
- | ' BBH Rate Adjusted. | ||
- | If column_ai(i, | ||
- | If column_ai(i, | ||
- | recalc_row = True | ||
- | End If | ||
- | End If | ||
- | | ||
- | | ||
- | ' BBH CCY Adjusted. | ||
- | If column_am(i, | ||
- | If column_am(i, | ||
- | recalc_row = True | ||
- | End If | ||
- | End If | ||
- | | ||
- | | ||
- | ' Suggested Rate Adjusted. | ||
- | If column_au(i, | ||
- | If column_au(i, | ||
- | recalc_row = True | ||
- | End If | ||
- | End If | ||
- | | ||
- | | ||
- | ' Check if recalc_row is true. | ||
- | If recalc_row = True Then | ||
- | | ||
- | ' Set recalc to true | ||
- | ' | ||
- | | ||
- | If (i > 2) Then ' | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | End If | ||
- | End If | ||
- | | ||
- | NextIteration2: | ||
- | Next i | ||
- | End With | ||
- | |||
- | |||
- | ' | ||
- | ' Check FinalABC for adjustment changes. | ||
- | |||
- | ' Loop through every row in SHEETNAME1 and check if any adjusted cell differs from the original. | ||
- | ' If so then continues with the recalc. | ||
- | For i = 2 To lastrow_FinalABC | ||
- | | ||
- | ' Default to false | ||
- | recalc_row = False | ||
- | recalc = False | ||
- | | ||
- | | ||
- | ' Check FinalABC for changes. | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' USD Adjustments. | ||
- | If .Range(" | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' Tax Rate Adjusted | ||
- | If .Range(" | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' Adjusted date. | ||
- | tmpMonth1 = UCase(Left(.Range(" | ||
- | tmpMonth2 = UCase(Left(Right(.Range(" | ||
- | | ||
- | If (tmpMonth1 <> tmpMonth2) Then | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' Check if recalc_row is true. | ||
- | If recalc_row = True Then | ||
- | | ||
- | ' Set recalc to true | ||
- | recalc = True | ||
- | | ||
- | | ||
- | ' Convert all formula cells in the row back to formulae. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Recalculate the entire row. | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Get starting position of the affected ISIN within the SHEETNAME1 sheet. | ||
- | FinalABC_ISIN = .Range(" | ||
- | End If | ||
- | | ||
- | End With | ||
- | | ||
- | | ||
- | If recalc = True Then | ||
- | | ||
- | ' Do refresh of Mapping pivots | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Refresh the pivots. | ||
- | For Each pt In .PivotTables | ||
- | pt.RefreshTable | ||
- | pt.Update | ||
- | Next | ||
- | | ||
- | End With | ||
- | | ||
- | | ||
- | ' Now get index of first row in SHEETNAME1 sheet that contains same affected ISIN. | ||
- | With .Sheets(" | ||
- | | ||
- | Set rng = .Range(" | ||
- | | ||
- | If WorksheetFunction.CountIf(rng, | ||
- | | ||
- | var = WorksheetFunction.Match(FinalABC_ISIN, | ||
- | | ||
- | If Not IsError(var) Then | ||
- | | ||
- | J = var | ||
- | SHEETNAME1_ISIN = .Range(" | ||
- | | ||
- | | ||
- | ' For every row that has same ISIN re-enable formulae in SHEETNAME1 sheet. | ||
- | ' Convert all formula cells in the row back to formulae. | ||
- | While .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Recalculate the entire row. | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' next row | ||
- | J = J + 1 | ||
- | Wend | ||
- | | ||
- | Else | ||
- | Message "The ISIN " & FinalABC_ISIN & " cannot be found in the SHEETNAME1 sheet." | ||
- | End If | ||
- | End If | ||
- | | ||
- | End With | ||
- | | ||
- | | ||
- | ' Recalculate all worksheets. | ||
- | Application.Calculate | ||
- | | ||
- | | ||
- | ' Now convert all impacted formulae back to values. | ||
- | 'TODO. loop through SHEETNAME1 as above and change formulae to values for any row impacted. | ||
- | | ||
- | | ||
- | ' Convert all formulae on the FinalABC sheet to values. | ||
- | If (i > 2) Then ' | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | End With | ||
- | End If | ||
- | | ||
- | | ||
- | | ||
- | ' Convert all formulae on the SHEETNAME1 sheet to values. | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Now get index of first row in SHEETNAME1 sheet that contains same affected ISIN. | ||
- | Set rng = .Range(" | ||
- | | ||
- | If WorksheetFunction.CountIf(rng, | ||
- | | ||
- | var = WorksheetFunction.Match(FinalABC_ISIN, | ||
- | | ||
- | If Not IsError(var) Then | ||
- | | ||
- | J = var | ||
- | SHEETNAME1_ISIN = .Range(" | ||
- | | ||
- | | ||
- | ' For every row that has same ISIN re-enable formulae in SHEETNAME1 sheet. | ||
- | ' Convert all formula cells in the row back to values. | ||
- | While .Range(" | ||
- | If (J > 2) Then ' | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | End If | ||
- | | ||
- | ' next row | ||
- | J = J + 1 | ||
- | Wend | ||
- | Else | ||
- | Message "The ISIN " & FinalABC_ISIN & " cannot be found in the SHEETNAME1 sheet." | ||
- | End If | ||
- | End If | ||
- | End With | ||
- | End If | ||
- | Next i | ||
- | End With | ||
- | |||
- | |||
- | ' Clear all objects. | ||
- | Set pt = Nothing | ||
- | Set rng = Nothing | ||
- | Set var = Nothing | ||
- | Set working = Nothing | ||
- | Set column_k = Nothing | ||
- | Set column_y = Nothing | ||
- | Set column_ac = Nothing | ||
- | Set column_ad = Nothing | ||
- | Set column_ae = Nothing | ||
- | Set column_af = Nothing | ||
- | Set column_ah = Nothing | ||
- | Set column_ai = Nothing | ||
- | Set column_al = Nothing | ||
- | Set column_am = Nothing | ||
- | Set column_at = Nothing | ||
- | Set column_au = Nothing | ||
- | | ||
- | End Sub | ||
- | |||
- | |||
- | ' For any row that has adjusted values different than the original value it recalculates the values against that row. | ||
- | ' It does this by putting formulae back in only for the specific row and then performing the recalc. | ||
- | ' Later the formula are replaced by values again. | ||
- | Sub M11205_Recalc_changed_adjusted_rows_Array_NEW() | ||
- | |||
- | Dim lastrow_SHEETNAME1 As Long | ||
- | Dim lastrow_FinalABC As Long | ||
- | |||
- | Dim recalc As Boolean | ||
- | Dim recalc_row As Boolean | ||
- | |||
- | Dim FinalABC_ISIN As String | ||
- | Dim SHEETNAME1_ISIN As String | ||
- | Dim rng As Range | ||
- | Dim var As Variant | ||
- | |||
- | Dim i As Long | ||
- | Dim J As Long | ||
- | |||
- | Dim tmpMonth1 As String | ||
- | Dim tmpMonth2 As String | ||
- | |||
- | Dim pt As PivotTable | ||
- | | ||
- | Dim column_k As Variant | ||
- | Dim column_y As Variant | ||
- | Dim column_ac As Variant | ||
- | Dim column_ad As Variant | ||
- | Dim column_ae As Variant | ||
- | Dim column_af As Variant | ||
- | Dim column_ah As Variant | ||
- | Dim column_ai As Variant | ||
- | Dim column_al As Variant | ||
- | Dim column_am As Variant | ||
- | Dim column_at As Variant | ||
- | Dim column_au As Variant | ||
- | |||
- | Dim working As Variant | ||
- | | ||
- | | ||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | | ||
- | | ||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | | ||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_SHEETNAME1 = .Sheets(" | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_SHEETNAME1 < 3 Then | ||
- | lastrow_SHEETNAME1 = 3 | ||
- | End If | ||
- | | ||
- | lastrow_FinalABC = .Sheets(" | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_FinalABC < 3 Then | ||
- | lastrow_FinalABC = 3 | ||
- | End If | ||
- | | ||
- | | ||
- | ' Loop through every row in SHEETNAME1 and check if any adjusted cell differs from the original. | ||
- | ' If so then continues with the recalc. | ||
- | recalc = False | ||
- | | ||
- | | ||
- | ReDim working(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_k(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_y(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_ac(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_ad(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_ae(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_af(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_ah(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_ai(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_al(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_am(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_at(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_au(1 To lastrow_SHEETNAME1, | ||
- | | ||
- | |||
- | ' Check SHEETNAME1 for changes. | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Load working with dummy values - just to set its size. | ||
- | working = .Range(" | ||
- | | ||
- | | ||
- | ' Load SHEETNAME1 columns into array variables. | ||
- | column_k = .Range(" | ||
- | column_y = .Range(" | ||
- | column_ac = .Range(" | ||
- | column_ad = .Range(" | ||
- | column_ae = .Range(" | ||
- | column_af = .Range(" | ||
- | column_ah = .Range(" | ||
- | column_ai = .Range(" | ||
- | column_al = .Range(" | ||
- | column_am = .Range(" | ||
- | column_at = .Range(" | ||
- | column_au = .Range(" | ||
- | | ||
- | For i = LBound(working) To UBound(working) | ||
- | | ||
- | ' If row 1, heading, skip | ||
- | If i = 1 Then | ||
- | GoTo NextIteration ' next i | ||
- | End If | ||
- | | ||
- | | ||
- | ' Default to false | ||
- | recalc_row = False | ||
- | | ||
- | | ||
- | ' Tax rate adjusted. | ||
- | If column_k(i, 1) <> "" | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' Include / Exclude. | ||
- | If column_y(i, 1) <> " | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' Income Code Adjusted. | ||
- | If column_ad(i, | ||
- | If column_ad(i, | ||
- | recalc_row = True | ||
- | End If | ||
- | End If | ||
- | | ||
- | | ||
- | ' Exemption Code Adjusted. | ||
- | If column_af(i, | ||
- | If column_af(i, | ||
- | recalc_row = True | ||
- | End If | ||
- | End If | ||
- | | ||
- | | ||
- | ' BBH Rate Adjusted. | ||
- | If column_ai(i, | ||
- | If column_ai(i, | ||
- | recalc_row = True | ||
- | End If | ||
- | End If | ||
- | | ||
- | | ||
- | ' BBH CCY Adjusted. | ||
- | If column_am(i, | ||
- | If column_am(i, | ||
- | recalc_row = True | ||
- | End If | ||
- | End If | ||
- | | ||
- | | ||
- | ' Suggested Rate Adjusted. | ||
- | If column_au(i, | ||
- | If column_au(i, | ||
- | recalc_row = True | ||
- | End If | ||
- | End If | ||
- | | ||
- | | ||
- | ' Check if recalc_row is true. | ||
- | If recalc_row = True Then | ||
- | ' Set recalc to true | ||
- | recalc = True | ||
- | | ||
- | | ||
- | ' Get starting position of the affected ISIN within the SHEETNAME1 sheet. | ||
- | SHEETNAME1_ISIN = .Range(" | ||
- | | ||
- | | ||
- | ' Convert all formula cells in the row back to formulae. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Recalculate the entire row. | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' | ||
- | ' TODO - Add in here loop for all affected lines in FinalABC sheet with same ISIN. | ||
- | ' Then we can remove the below copy all BBH formulae down. | ||
- | | ||
- | | ||
- | ' Now get index of first row in FinalABC sheet that contains same affected ISIN. | ||
- | With Sheets(" | ||
- | | ||
- | Set rng = .Range(" | ||
- | | ||
- | If WorksheetFunction.CountIf(rng, | ||
- | | ||
- | var = WorksheetFunction.Match(SHEETNAME1_ISIN, | ||
- | | ||
- | If Not IsError(var) Then | ||
- | | ||
- | J = var | ||
- | FinalABC_ISIN = .Range(" | ||
- | | ||
- | | ||
- | ' For every row that has same ISIN re-enable formulae in SHEETNAME1 sheet. | ||
- | ' Convert all formula cells in the row back to formulae. | ||
- | While .Range(" | ||
- | | ||
- | ' Convert all formula cells in the row back to formulae. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Recalculate the entire row. | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Convert all formulae on the FinalABC sheet to values. | ||
- | If (J > 2) Then | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | End If | ||
- | | ||
- | ' next row | ||
- | J = J + 1 | ||
- | Wend | ||
- | | ||
- | Else | ||
- | Message "The ISIN " & SHEETNAME1_ISIN & " cannot be found in the FinalABC sheet." | ||
- | End If | ||
- | End If | ||
- | End With | ||
- | | ||
- | | ||
- | | ||
- | ' Convert all formulae on the SHEETNAME1 sheet to values. | ||
- | If (i > 2) Then | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | |||
- | End If | ||
- | | ||
- | ' | ||
- | End If | ||
- | | ||
- | | ||
- | | ||
- | NextIteration: | ||
- | |||
- | Next i | ||
- | End With | ||
- | |||
- | |||
- | |||
- | If recalc = True Then | ||
- | | ||
- | ' Do refresh of pivots. | ||
- | With Sheets(" | ||
- | | ||
- | ' Activate the Mapping Pivots sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Refresh the pivot tables. | ||
- | For Each pt In .PivotTables | ||
- | pt.RefreshTable | ||
- | pt.Update | ||
- | Next | ||
- | | ||
- | End With | ||
- | | ||
- | End If | ||
- | |||
- | |||
- | |||
- | |||
- | ' | ||
- | ' Check FinalABC for adjustment changes. | ||
- | |||
- | ' Loop through every row in SHEETNAME1 and check if any adjusted cell differs from the original. | ||
- | ' If so then continues with the recalc. | ||
- | For i = 2 To lastrow_FinalABC | ||
- | | ||
- | ' Default to false | ||
- | recalc_row = False | ||
- | recalc = False | ||
- | | ||
- | | ||
- | ' Check FinalABC for changes. | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' USD Adjustments. | ||
- | If .Range(" | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' Tax Rate Adjusted | ||
- | If .Range(" | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' Adjusted date. | ||
- | tmpMonth1 = UCase(Left(.Range(" | ||
- | tmpMonth2 = UCase(Left(Right(.Range(" | ||
- | | ||
- | If (tmpMonth1 <> tmpMonth2) Then | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' Check if recalc_row is true. | ||
- | If recalc_row = True Then | ||
- | | ||
- | ' Set recalc to true | ||
- | recalc = True | ||
- | | ||
- | | ||
- | ' Convert all formula cells in the row back to formulae. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Recalculate the entire row. | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Get starting position of the affected ISIN within the SHEETNAME1 sheet. | ||
- | FinalABC_ISIN = .Range(" | ||
- | End If | ||
- | | ||
- | End With | ||
- | | ||
- | | ||
- | If recalc = True Then | ||
- | | ||
- | ' Do refresh of Mapping pivots | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Refresh the pivots. | ||
- | For Each pt In .PivotTables | ||
- | pt.RefreshTable | ||
- | pt.Update | ||
- | Next | ||
- | | ||
- | End With | ||
- | | ||
- | | ||
- | ' Now get index of first row in SHEETNAME1 sheet that contains same affected ISIN. | ||
- | With .Sheets(" | ||
- | | ||
- | Set rng = .Range(" | ||
- | | ||
- | If WorksheetFunction.CountIf(rng, | ||
- | | ||
- | var = WorksheetFunction.Match(FinalABC_ISIN, | ||
- | | ||
- | If Not IsError(var) Then | ||
- | | ||
- | J = var | ||
- | SHEETNAME1_ISIN = .Range(" | ||
- | | ||
- | | ||
- | ' For every row that has same ISIN re-enable formulae in SHEETNAME1 sheet. | ||
- | ' Convert all formula cells in the row back to formulae. | ||
- | While .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Recalculate the entire row. | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' next row | ||
- | J = J + 1 | ||
- | Wend | ||
- | | ||
- | Else | ||
- | Message "The ISIN " & SHEETNAME1_ISIN & " cannot be found in the FinalABC sheet." | ||
- | End If | ||
- | End If | ||
- | | ||
- | End With | ||
- | | ||
- | | ||
- | ' Recalculate all worksheets. | ||
- | Application.Calculate | ||
- | | ||
- | | ||
- | ' Now convert all impacted formulae back to values. | ||
- | 'TODO. loop through SHEETNAME1 as above and change formulae to values for any row impacted. | ||
- | | ||
- | | ||
- | ' Convert all formulae on the FinalABC sheet to values. | ||
- | If (i > 2) Then ' | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | End With | ||
- | End If | ||
- | | ||
- | | ||
- | | ||
- | ' Convert all formulae on the SHEETNAME1 sheet to values. | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Now get index of first row in SHEETNAME1 sheet that contains same affected ISIN. | ||
- | Set rng = .Range(" | ||
- | | ||
- | If WorksheetFunction.CountIf(rng, | ||
- | | ||
- | var = WorksheetFunction.Match(FinalABC_ISIN, | ||
- | | ||
- | If Not IsError(var) Then | ||
- | | ||
- | J = var | ||
- | SHEETNAME1_ISIN = .Range(" | ||
- | | ||
- | | ||
- | ' For every row that has same ISIN re-enable formulae in SHEETNAME1 sheet. | ||
- | ' Convert all formula cells in the row back to values. | ||
- | While .Range(" | ||
- | If (J > 2) Then ' | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | End If | ||
- | | ||
- | ' next row | ||
- | J = J + 1 | ||
- | Wend | ||
- | Else | ||
- | Message "The ISIN " & FinalABC_ISIN & " cannot be found in the SHEETNAME1 sheet." | ||
- | End If | ||
- | End If | ||
- | End With | ||
- | End If | ||
- | Next i | ||
- | End With | ||
- | |||
- | |||
- | ' Clear all objects. | ||
- | Set pt = Nothing | ||
- | Set rng = Nothing | ||
- | Set var = Nothing | ||
- | Set working = Nothing | ||
- | Set column_k = Nothing | ||
- | Set column_y = Nothing | ||
- | Set column_ac = Nothing | ||
- | Set column_ad = Nothing | ||
- | Set column_ae = Nothing | ||
- | Set column_af = Nothing | ||
- | Set column_ah = Nothing | ||
- | Set column_ai = Nothing | ||
- | Set column_al = Nothing | ||
- | Set column_am = Nothing | ||
- | Set column_at = Nothing | ||
- | Set column_au = Nothing | ||
- | | ||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' For any row that has adjusted values different than the original value it recalculates the values against that row. | ||
- | ' It does this by putting formulae back in only for the specific row and then performing the recalc. | ||
- | ' Later the formula are replaced by values again. | ||
- | Sub M11207_Recalc_changed_adjusted_rows_Array_NEW() | ||
- | |||
- | Dim lastrow_SHEETNAME1 As Long | ||
- | Dim lastrow_FinalABC As Long | ||
- | |||
- | Dim recalc As Boolean | ||
- | Dim recalc_row As Boolean | ||
- | |||
- | Dim FinalABC_ISIN As String | ||
- | Dim SHEETNAME1_ISIN As String | ||
- | Dim rng As Range | ||
- | Dim var As Variant | ||
- | |||
- | Dim i As Long | ||
- | Dim J As Long | ||
- | |||
- | Dim tmpMonth1 As String | ||
- | Dim tmpMonth2 As String | ||
- | |||
- | Dim pt As PivotTable | ||
- | | ||
- | Dim column_k As Variant | ||
- | Dim column_y As Variant | ||
- | Dim column_ac As Variant | ||
- | Dim column_ad As Variant | ||
- | Dim column_ae As Variant | ||
- | Dim column_af As Variant | ||
- | Dim column_ah As Variant | ||
- | Dim column_ai As Variant | ||
- | Dim column_al As Variant | ||
- | Dim column_am As Variant | ||
- | Dim column_at As Variant | ||
- | Dim column_au As Variant | ||
- | |||
- | Dim working As Variant | ||
- | | ||
- | | ||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | | ||
- | | ||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | | ||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_SHEETNAME1 = .Sheets(" | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_SHEETNAME1 < 3 Then | ||
- | lastrow_SHEETNAME1 = 3 | ||
- | End If | ||
- | | ||
- | lastrow_FinalABC = .Sheets(" | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_FinalABC < 3 Then | ||
- | lastrow_FinalABC = 3 | ||
- | End If | ||
- | | ||
- | | ||
- | ' Loop through every row in SHEETNAME1 and check if any adjusted cell differs from the original. | ||
- | ' If so then continues with the recalc. | ||
- | recalc = False | ||
- | | ||
- | | ||
- | ReDim working(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_k(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_y(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_ac(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_ad(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_ae(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_af(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_ah(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_ai(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_al(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_am(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_at(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_au(1 To lastrow_SHEETNAME1, | ||
- | | ||
- | |||
- | ' Check SHEETNAME1 for changes. | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Load working with dummy values - just to set its size. | ||
- | working = .Range(" | ||
- | | ||
- | | ||
- | ' Load SHEETNAME1 columns into array variables. | ||
- | column_k = .Range(" | ||
- | column_y = .Range(" | ||
- | column_ac = .Range(" | ||
- | column_ad = .Range(" | ||
- | column_ae = .Range(" | ||
- | column_af = .Range(" | ||
- | column_ah = .Range(" | ||
- | column_ai = .Range(" | ||
- | column_al = .Range(" | ||
- | column_am = .Range(" | ||
- | column_at = .Range(" | ||
- | column_au = .Range(" | ||
- | | ||
- | | ||
- | ' Prompt the user for the row to change | ||
- | i = Application.InputBox _ | ||
- | (Prompt: | ||
- | Title: | ||
- | |||
- | If i < LBound(working) Then | ||
- | GoTo IncorrectRow | ||
- | End If | ||
- | | ||
- | If i > UBound(working) Then | ||
- | GoTo IncorrectRow | ||
- | End If | ||
- | | ||
- | | ||
- | | ||
- | 'For i = LBound(working) To UBound(working) | ||
- | | ||
- | ' If row 1, heading, skip | ||
- | If i = 1 Then | ||
- | GoTo IncorrectRow ' next i | ||
- | End If | ||
- | | ||
- | | ||
- | ' Default to false | ||
- | recalc_row = False | ||
- | | ||
- | | ||
- | ' Tax rate adjusted. | ||
- | If column_k(i, 1) <> "" | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' Include / Exclude. | ||
- | If column_y(i, 1) <> " | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' Income Code Adjusted. | ||
- | If column_ad(i, | ||
- | If column_ad(i, | ||
- | recalc_row = True | ||
- | End If | ||
- | End If | ||
- | | ||
- | | ||
- | ' Exemption Code Adjusted. | ||
- | If column_af(i, | ||
- | If column_af(i, | ||
- | recalc_row = True | ||
- | End If | ||
- | End If | ||
- | | ||
- | | ||
- | ' BBH Rate Adjusted. | ||
- | If column_ai(i, | ||
- | If column_ai(i, | ||
- | recalc_row = True | ||
- | End If | ||
- | End If | ||
- | | ||
- | | ||
- | ' BBH CCY Adjusted. | ||
- | If column_am(i, | ||
- | If column_am(i, | ||
- | recalc_row = True | ||
- | End If | ||
- | End If | ||
- | | ||
- | | ||
- | ' Suggested Rate Adjusted. | ||
- | If column_au(i, | ||
- | If column_au(i, | ||
- | recalc_row = True | ||
- | End If | ||
- | End If | ||
- | | ||
- | | ||
- | ' Check if recalc_row is true. | ||
- | If recalc_row = True Then | ||
- | ' Set recalc to true | ||
- | recalc = True | ||
- | | ||
- | | ||
- | ' Get starting position of the affected ISIN within the SHEETNAME1 sheet. | ||
- | SHEETNAME1_ISIN = .Range(" | ||
- | | ||
- | | ||
- | ' Convert all formula cells in the row back to formulae. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Recalculate the entire row. | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' | ||
- | ' TODO - Add in here loop for all affected lines in FinalABC sheet with same ISIN. | ||
- | ' Then we can remove the below copy all BBH formulae down. | ||
- | | ||
- | | ||
- | ' Now get index of first row in FinalABC sheet that contains same affected ISIN. | ||
- | With Sheets(" | ||
- | | ||
- | Set rng = .Range(" | ||
- | | ||
- | If WorksheetFunction.CountIf(rng, | ||
- | | ||
- | var = WorksheetFunction.Match(SHEETNAME1_ISIN, | ||
- | | ||
- | If Not IsError(var) Then | ||
- | | ||
- | J = var | ||
- | FinalABC_ISIN = .Range(" | ||
- | | ||
- | | ||
- | ' For every row that has same ISIN re-enable formulae in SHEETNAME1 sheet. | ||
- | ' Convert all formula cells in the row back to formulae. | ||
- | While .Range(" | ||
- | | ||
- | ' Convert all formula cells in the row back to formulae. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Recalculate the entire row. | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Convert all formulae on the FinalABC sheet to values. | ||
- | If (J > 2) Then | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | End If | ||
- | | ||
- | ' next row | ||
- | J = J + 1 | ||
- | Wend | ||
- | | ||
- | Else | ||
- | Message "The ISIN " & SHEETNAME1_ISIN & " cannot be found in the FinalABC sheet." | ||
- | End If | ||
- | End If | ||
- | End With | ||
- | | ||
- | | ||
- | | ||
- | ' Convert all formulae on the SHEETNAME1 sheet to values. | ||
- | If (i > 2) Then | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | |||
- | End If | ||
- | | ||
- | ' | ||
- | End If | ||
- | | ||
- | | ||
- | | ||
- | IncorrectRow: | ||
- | |||
- | 'Next i | ||
- | End With | ||
- | |||
- | |||
- | |||
- | If recalc = True Then | ||
- | | ||
- | ' Do refresh of pivots. | ||
- | With Sheets(" | ||
- | | ||
- | ' Activate the Mapping Pivots sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Refresh the pivot tables. | ||
- | For Each pt In .PivotTables | ||
- | pt.RefreshTable | ||
- | pt.Update | ||
- | Next | ||
- | | ||
- | End With | ||
- | | ||
- | End If | ||
- | End With | ||
- | |||
- | |||
- | ' Clear all objects. | ||
- | Set pt = Nothing | ||
- | Set rng = Nothing | ||
- | Set var = Nothing | ||
- | Set working = Nothing | ||
- | Set column_k = Nothing | ||
- | Set column_y = Nothing | ||
- | Set column_ac = Nothing | ||
- | Set column_ad = Nothing | ||
- | Set column_ae = Nothing | ||
- | Set column_af = Nothing | ||
- | Set column_ah = Nothing | ||
- | Set column_ai = Nothing | ||
- | Set column_al = Nothing | ||
- | Set column_am = Nothing | ||
- | Set column_at = Nothing | ||
- | Set column_au = Nothing | ||
- | | ||
- | End Sub | ||
- | |||
- | |||
- | ' For any row that has adjusted values different than the original value it recalculates the values against that row. | ||
- | ' It does this by putting formulae back in only for the specific row and then performing the recalc. | ||
- | ' Later the formula are replaced by values again. | ||
- | Sub M11208_Recalc_changed_adjusted_rows_Array_NEW() | ||
- | |||
- | Dim lastrow_SHEETNAME1 As Long | ||
- | Dim lastrow_FinalABC As Long | ||
- | |||
- | Dim recalc As Boolean | ||
- | Dim recalc_row As Boolean | ||
- | |||
- | Dim FinalABC_ISIN As String | ||
- | Dim SHEETNAME1_ISIN As String | ||
- | Dim rng As Range | ||
- | Dim var As Variant | ||
- | |||
- | Dim i As Long | ||
- | Dim J As Long | ||
- | |||
- | Dim tmpMonth1 As String | ||
- | Dim tmpMonth2 As String | ||
- | |||
- | Dim pt As PivotTable | ||
- | | ||
- | Dim column_k As Variant | ||
- | Dim column_y As Variant | ||
- | Dim column_ac As Variant | ||
- | Dim column_ad As Variant | ||
- | Dim column_ae As Variant | ||
- | Dim column_af As Variant | ||
- | Dim column_ah As Variant | ||
- | Dim column_ai As Variant | ||
- | Dim column_al As Variant | ||
- | Dim column_am As Variant | ||
- | Dim column_at As Variant | ||
- | Dim column_au As Variant | ||
- | |||
- | Dim working As Variant | ||
- | | ||
- | | ||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | | ||
- | | ||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | | ||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_SHEETNAME1 = .Sheets(" | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_SHEETNAME1 < 3 Then | ||
- | lastrow_SHEETNAME1 = 3 | ||
- | End If | ||
- | | ||
- | lastrow_FinalABC = .Sheets(" | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_FinalABC < 3 Then | ||
- | lastrow_FinalABC = 3 | ||
- | End If | ||
- | | ||
- | | ||
- | ' Loop through every row in SHEETNAME1 and check if any adjusted cell differs from the original. | ||
- | ' If so then continues with the recalc. | ||
- | recalc = False | ||
- | | ||
- | | ||
- | ReDim working(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_k(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_y(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_ac(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_ad(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_ae(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_af(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_ah(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_ai(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_al(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_am(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_at(1 To lastrow_SHEETNAME1, | ||
- | ReDim column_au(1 To lastrow_SHEETNAME1, | ||
- | | ||
- | |||
- | If recalc = True Then | ||
- | | ||
- | ' Do refresh of pivots. | ||
- | With Sheets(" | ||
- | | ||
- | ' Activate the Mapping Pivots sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Refresh the pivot tables. | ||
- | For Each pt In .PivotTables | ||
- | pt.RefreshTable | ||
- | pt.Update | ||
- | Next | ||
- | | ||
- | End With | ||
- | | ||
- | End If | ||
- | |||
- | |||
- | |||
- | |||
- | ' | ||
- | ' Check FinalABC for adjustment changes. | ||
- | |||
- | ' Loop through every row in SHEETNAME1 and check if any adjusted cell differs from the original. | ||
- | ' If so then continues with the recalc. | ||
- | | ||
- | | ||
- | i = Application.InputBox _ | ||
- | (Prompt: | ||
- | Title: | ||
- | |||
- | If i < LBound(working) Then | ||
- | GoTo IncorrectRow | ||
- | End If | ||
- | | ||
- | If i > UBound(working) Then | ||
- | GoTo IncorrectRow | ||
- | End If | ||
- | | ||
- | | ||
- | 'For i = 2 To lastrow_FinalABC | ||
- | | ||
- | ' Default to false | ||
- | recalc_row = False | ||
- | recalc = False | ||
- | | ||
- | | ||
- | ' Check FinalABC for changes. | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | ' USD Adjustments. | ||
- | If .Range(" | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' Tax Rate Adjusted | ||
- | If .Range(" | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' Adjusted date. | ||
- | tmpMonth1 = UCase(Left(.Range(" | ||
- | tmpMonth2 = UCase(Left(Right(.Range(" | ||
- | | ||
- | If (tmpMonth1 <> tmpMonth2) Then | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' Check if recalc_row is true. | ||
- | If recalc_row = True Then | ||
- | | ||
- | ' Set recalc to true | ||
- | recalc = True | ||
- | | ||
- | | ||
- | ' Convert all formula cells in the row back to formulae. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Recalculate the entire row. | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Get starting position of the affected ISIN within the SHEETNAME1 sheet. | ||
- | FinalABC_ISIN = .Range(" | ||
- | End If | ||
- | | ||
- | End With | ||
- | | ||
- | | ||
- | If recalc = True Then | ||
- | | ||
- | ' Do refresh of Mapping pivots | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Refresh the pivots. | ||
- | For Each pt In .PivotTables | ||
- | pt.RefreshTable | ||
- | pt.Update | ||
- | Next | ||
- | | ||
- | End With | ||
- | | ||
- | | ||
- | ' Now get index of first row in SHEETNAME1 sheet that contains same affected ISIN. | ||
- | With .Sheets(" | ||
- | | ||
- | Set rng = .Range(" | ||
- | | ||
- | If WorksheetFunction.CountIf(rng, | ||
- | | ||
- | var = WorksheetFunction.Match(FinalABC_ISIN, | ||
- | | ||
- | If Not IsError(var) Then | ||
- | | ||
- | J = var | ||
- | SHEETNAME1_ISIN = .Range(" | ||
- | | ||
- | | ||
- | ' For every row that has same ISIN re-enable formulae in SHEETNAME1 sheet. | ||
- | ' Convert all formula cells in the row back to formulae. | ||
- | While .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Recalculate the entire row. | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' next row | ||
- | J = J + 1 | ||
- | Wend | ||
- | | ||
- | Else | ||
- | Message "The ISIN " & SHEETNAME1_ISIN & " cannot be found in the FinalABC sheet." | ||
- | End If | ||
- | End If | ||
- | | ||
- | End With | ||
- | | ||
- | | ||
- | ' Recalculate all worksheets. | ||
- | Application.Calculate | ||
- | | ||
- | | ||
- | ' Now convert all impacted formulae back to values. | ||
- | 'TODO. loop through SHEETNAME1 as above and change formulae to values for any row impacted. | ||
- | | ||
- | | ||
- | ' Convert all formulae on the FinalABC sheet to values. | ||
- | If (i > 2) Then ' | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | End With | ||
- | End If | ||
- | | ||
- | | ||
- | | ||
- | ' Convert all formulae on the SHEETNAME1 sheet to values. | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Now get index of first row in SHEETNAME1 sheet that contains same affected ISIN. | ||
- | Set rng = .Range(" | ||
- | | ||
- | If WorksheetFunction.CountIf(rng, | ||
- | | ||
- | var = WorksheetFunction.Match(FinalABC_ISIN, | ||
- | | ||
- | If Not IsError(var) Then | ||
- | | ||
- | J = var | ||
- | SHEETNAME1_ISIN = .Range(" | ||
- | | ||
- | | ||
- | ' For every row that has same ISIN re-enable formulae in SHEETNAME1 sheet. | ||
- | ' Convert all formula cells in the row back to values. | ||
- | While .Range(" | ||
- | If (J > 2) Then ' | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | End If | ||
- | | ||
- | ' next row | ||
- | J = J + 1 | ||
- | Wend | ||
- | Else | ||
- | Message "The ISIN " & FinalABC_ISIN & " cannot be found in the SHEETNAME1 sheet." | ||
- | End If | ||
- | End If | ||
- | End With | ||
- | End If | ||
- | IncorrectRow: | ||
- | 'Next i | ||
- | | ||
- | End With | ||
- | |||
- | |||
- | ' Clear all objects. | ||
- | Set pt = Nothing | ||
- | Set rng = Nothing | ||
- | Set var = Nothing | ||
- | Set working = Nothing | ||
- | Set column_k = Nothing | ||
- | Set column_y = Nothing | ||
- | Set column_ac = Nothing | ||
- | Set column_ad = Nothing | ||
- | Set column_ae = Nothing | ||
- | Set column_af = Nothing | ||
- | Set column_ah = Nothing | ||
- | Set column_ai = Nothing | ||
- | Set column_al = Nothing | ||
- | Set column_am = Nothing | ||
- | Set column_at = Nothing | ||
- | Set column_au = Nothing | ||
- | | ||
- | End Sub | ||
- | |||
- | |||
- | |||
- | |||
- | ' For any row that has adjusted values different than the original value it recalculates the values against that row. | ||
- | ' It does this by putting formulae back in only for the specific row and then performing the recalc. | ||
- | ' Later the formula are replaced by values again. | ||
- | Sub M11210_Recalc_changed_adjusted_rows() | ||
- | |||
- | Dim lastrow_SHEETNAME1 As Long | ||
- | Dim lastrow_FinalABC As Long | ||
- | |||
- | Dim sheet As Worksheet | ||
- | |||
- | Dim recalc As Boolean | ||
- | Dim recalc_row As Boolean | ||
- | |||
- | Dim FinalABC_ISIN As String | ||
- | Dim SHEETNAME1_ISIN As String | ||
- | Dim rng As Range | ||
- | Dim var As Variant | ||
- | |||
- | Dim i As Long | ||
- | Dim J As Long | ||
- | |||
- | Dim tmpMonth1 As String | ||
- | Dim tmpMonth2 As String | ||
- | |||
- | Dim pt As PivotTable | ||
- | | ||
- | | ||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | | ||
- | | ||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | | ||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_SHEETNAME1 = .Sheets(" | ||
- | lastrow_FinalABC = .Sheets(" | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_SHEETNAME1 < 3 Then | ||
- | lastrow_SHEETNAME1 = 3 | ||
- | End If | ||
- | If lastrow_FinalABC < 3 Then | ||
- | lastrow_FinalABC = 3 | ||
- | End If | ||
- | | ||
- | | ||
- | ' Loop through every row in SHEETNAME1 and check if any adjusted cell differs from the original. | ||
- | ' If so then continues with the recalc. | ||
- | recalc = False | ||
- | | ||
- | | ||
- | |||
- | ' Check SHEETNAME1 for changes. | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | For i = 2 To lastrow_SHEETNAME1 | ||
- | 'For i = lastrow To lastrow ' for testing area below. | ||
- | | ||
- | ' Default to false | ||
- | recalc_row = False | ||
- | | ||
- | | ||
- | ' Tax rate adjusted. | ||
- | If .Range(" | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' Include / Exclude | ||
- | If .Range(" | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' Income Code Adjusted. | ||
- | If .Range(" | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' Exemption Code Adjusted. | ||
- | If .Range(" | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' BBH Rate Adjusted. | ||
- | If .Range(" | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' BBH CCY Adjusted. | ||
- | If .Range(" | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' Suggested Rate Adjusted. | ||
- | If .Range(" | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' Check if recalc_row is true. | ||
- | If recalc_row = True Then | ||
- | ' Set recalc to true | ||
- | recalc = True | ||
- | | ||
- | ' Convert all formula cells in the row back to formulae. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | ' Recalculate the entire row. | ||
- | .Range(" | ||
- | End If | ||
- | | ||
- | Next i | ||
- | End With | ||
- | |||
- | |||
- | If recalc = True Then | ||
- | | ||
- | ' Refresh all impacted formula on the FinalABC sheet. | ||
- | With Sheets(" | ||
- | | ||
- | ' Activate the FinalABC sheet. | ||
- | .Activate | ||
- | |||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | ' Recalculate the entire row. | ||
- | ' | ||
- | | ||
- | End With | ||
- | |||
- | | ||
- | ' Recalculate all worksheets. | ||
- | Application.Calculate | ||
- | | ||
- | | ||
- | ' Do refresh of pivots. | ||
- | With Sheets(" | ||
- | | ||
- | ' Activate the Mapping Pivots sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Refresh the pivot tables. | ||
- | For Each pt In .PivotTables | ||
- | pt.RefreshTable | ||
- | pt.Update | ||
- | Next | ||
- | | ||
- | End With | ||
- | | ||
- | | ||
- | ' Recalculate all worksheets again to pick up Pivot values. | ||
- | Application.Calculate | ||
- | | ||
- | | ||
- | ' Now convert all impacted formulae back to values. | ||
- | 'TODO. loop through SHEETNAME1 as above and change formulae to values for any row impacted. | ||
- | | ||
- | | ||
- | ' Convert all formulae on the FinalABC sheet to values. | ||
- | With Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | End With | ||
- | | ||
- | End If | ||
- | | ||
- | | ||
- | ' Convert all formulae on the SHEETNAME1 sheet to values. | ||
- | ' Loop through every row in SHEETNAME1 and check if any adjusted cell differs from the original. | ||
- | ' If so then continues with the changing of the formula back to values. | ||
- | recalc = False | ||
- | | ||
- | For i = 2 To lastrow_SHEETNAME1 | ||
- | | ||
- | ' Default to false | ||
- | recalc_row = False | ||
- | | ||
- | | ||
- | ' Check SHEETNAME1 for changes. | ||
- | With .Sheets(" | ||
- | | ||
- | ' Tax rate adjusted. | ||
- | If .Range(" | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' Include / Exclude | ||
- | If .Range(" | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' Income Code Adjusted. | ||
- | If .Range(" | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' Exemption Code Adjusted. | ||
- | If .Range(" | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' BBH Rate Adjusted. | ||
- | If .Range(" | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' BBH CCY Adjusted. | ||
- | If .Range(" | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' Suggested Rate Adjusted. | ||
- | If .Range(" | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' Check if recalc_row is true. | ||
- | If recalc_row = True Then | ||
- | | ||
- | ' Set recalc to true | ||
- | ' | ||
- | | ||
- | If (i > 2) Then ' | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | End If | ||
- | End If | ||
- | End With | ||
- | Next i | ||
- | | ||
- | |||
- | ' | ||
- | ' Check FinalABC for adjustment changes. | ||
- | |||
- | ' Loop through every row in SHEETNAME1 and check if any adjusted cell differs from the original. | ||
- | ' If so then continues with the recalc. | ||
- | recalc = False | ||
- | For i = 2 To lastrow_FinalABC | ||
- | | ||
- | ' Default to false | ||
- | recalc_row = False | ||
- | | ||
- | | ||
- | ' Check FinalABC for changes. | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' USD Adjustments. | ||
- | If .Range(" | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' Adjusted date. | ||
- | tmpMonth1 = UCase(Left(.Range(" | ||
- | tmpMonth2 = UCase(Left(Right(.Range(" | ||
- | | ||
- | If (tmpMonth1 <> tmpMonth2) Then | ||
- | recalc_row = True | ||
- | End If | ||
- | | ||
- | | ||
- | ' Check if recalc_row is true. | ||
- | If recalc_row = True Then | ||
- | | ||
- | ' Set recalc to true | ||
- | recalc = True | ||
- | | ||
- | | ||
- | ' Convert all formula cells in the row back to formulae. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | ' Recalculate the entire row. | ||
- | .Range(" | ||
- | | ||
- | ' Get starting position of the affected ISIN within the SHEETNAME1 sheet. | ||
- | FinalABC_ISIN = .Range(" | ||
- | End If | ||
- | | ||
- | End With | ||
- | | ||
- | | ||
- | ' Do refresh of Mapping pivots | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Refresh the pivots. | ||
- | For Each pt In .PivotTables | ||
- | pt.RefreshTable | ||
- | pt.Update | ||
- | Next | ||
- | | ||
- | End With | ||
- | | ||
- | | ||
- | ' Now get index of first row in SHEETNAME1 sheet that contains same affected ISIN. | ||
- | With .Sheets(" | ||
- | | ||
- | Set rng = .Range(" | ||
- | | ||
- | If WorksheetFunction.CountIf(rng, | ||
- | | ||
- | var = WorksheetFunction.Match(FinalABC_ISIN, | ||
- | | ||
- | If Not IsError(var) Then | ||
- | | ||
- | J = var | ||
- | SHEETNAME1_ISIN = .Range(" | ||
- | | ||
- | | ||
- | ' For every row that has same ISIN re-enable formulae in SHEETNAME1 sheet. | ||
- | ' Convert all formula cells in the row back to formulae. | ||
- | While .Range(" | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Recalculate the entire row. | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' next row | ||
- | J = J + 1 | ||
- | Wend | ||
- | Else | ||
- | MsgBox ("The ISIN " & FinalABC_ISIN & " cannot be found in the SHEETNAME1 sheet." | ||
- | End If | ||
- | End If | ||
- | | ||
- | End With | ||
- | | ||
- | | ||
- | ' Recalculate all worksheets. | ||
- | Application.Calculate | ||
- | | ||
- | | ||
- | ' Now convert all impacted formulae back to values. | ||
- | 'TODO. loop through SHEETNAME1 as above and change formulae to values for any row impacted. | ||
- | | ||
- | | ||
- | ' Convert all formulae on the FinalABC sheet to values. | ||
- | If (i > 2) Then ' | ||
- | | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | End With | ||
- | End If | ||
- | | ||
- | | ||
- | ' Convert all formulae on the SHEETNAME1 sheet to values. | ||
- | 'With Workbooks(my1042Rec).Sheets(" | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | 'End With | ||
- | | ||
- | | ||
- | | ||
- | ' Convert all formulae on the SHEETNAME1 sheet to values. | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Now get index of first row in SHEETNAME1 sheet that contains same affected ISIN. | ||
- | Set rng = .Range(" | ||
- | | ||
- | If WorksheetFunction.CountIf(rng, | ||
- | | ||
- | var = WorksheetFunction.Match(FinalABC_ISIN, | ||
- | | ||
- | If Not IsError(var) Then | ||
- | | ||
- | J = var | ||
- | SHEETNAME1_ISIN = .Range(" | ||
- | |||
- | | ||
- | ' For every row that has same ISIN re-enable formulae in SHEETNAME1 sheet. | ||
- | ' Convert all formula cells in the row back to values. | ||
- | While .Range(" | ||
- | If (J > 2) Then ' | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | End If | ||
- | | ||
- | ' next row | ||
- | J = J + 1 | ||
- | | ||
- | Wend | ||
- | Else | ||
- | MsgBox ("The ISIN " & FinalABC_ISIN & " cannot be found in the SHEETNAME1 sheet." | ||
- | End If | ||
- | End If | ||
- | | ||
- | End With | ||
- | | ||
- | Next i | ||
- | | ||
- | End With | ||
- | |||
- | |||
- | ' Clear all objects. | ||
- | Set pt = Nothing | ||
- | |||
- | End Sub | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | |||
- | |||
- | |||
- | |||
- | ' Copies all formulae down on the FinalABC sheet. | ||
- | ' Does not calculate. | ||
- | ' Does not change the formula to values. | ||
- | ' This may run for a very long time. Go have a coffee. | ||
- | Sub M12000_Copy_FinalABC_Formulae_Down() | ||
- | |||
- | Dim mycell As Variant | ||
- | Dim lastrow_FinalABC As Long | ||
- | Dim Pmt_Curr As Variant | ||
- | Dim FX_Rate As Variant | ||
- | |||
- | |||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | | ||
- | | ||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | |||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | |||
- | |||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | ' | ||
- | lastrow_FinalABC = .Cells(Rows.Count, | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_FinalABC < 3 Then | ||
- | lastrow_FinalABC = 3 | ||
- | End If | ||
- | |||
- | |||
- | ' Ensure that FX_Rate has a default value. | ||
- | 'For Each mycell In Workbooks(my1042Rec).Sheets(" | ||
- | For Each mycell In .Range(" | ||
- | If Not mycell Like " | ||
- | Next mycell | ||
- | |||
- | |||
- | ' Copies formulae down. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | |||
- | |||
- | ' Calculations. | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | |||
- | |||
- | ' Now copy and paste formula ranges as values to speed up the file processing. | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | |||
- | 'For Each Pmt_Curr In Sheets(" | ||
- | 'For Each Pmt_Curr In Sheets(" | ||
- | For Each Pmt_Curr In Sheets(" | ||
- | If RTrim(LTrim(Pmt_Curr)) = "" | ||
- | Next Pmt_Curr | ||
- | |||
- | |||
- | 'For Each FX_Rate In Sheets(" | ||
- | 'For Each FX_Rate In Sheets(" | ||
- | For Each FX_Rate In Sheets(" | ||
- | If IsNumeric(FX_Rate) = False Then FX_Rate.Value = 1 | ||
- | Next FX_Rate | ||
- | |||
- | |||
- | ' Select A1. | ||
- | ScrollTo ActiveSheet.name, | ||
- | End With | ||
- | End With | ||
- | | ||
- | | ||
- | ' Clear all objects. | ||
- | Set mycell = Nothing | ||
- | Set Pmt_Curr = Nothing | ||
- | Set FX_Rate = Nothing | ||
- | | ||
- | End Sub | ||
- | |||
- | |||
- | |||
- | ' Converts all formulae on the FinalABC sheet to Values. | ||
- | ' Does not change row 2 of the FinalABC sheet. | ||
- | ' This may run for a very long time. Go have a coffee. | ||
- | Sub M12010_Convert_FinalABC_Formulae_to_Values() | ||
- | |||
- | Dim lastrow_FinalABC As Long | ||
- | |||
- | |||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | | ||
- | | ||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | |||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | |||
- | |||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | ' | ||
- | lastrow_FinalABC = .Cells(Rows.Count, | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_FinalABC < 3 Then | ||
- | lastrow_FinalABC = 3 | ||
- | End If | ||
- | |||
- | |||
- | ' Now copy and paste formula ranges as values to speed up the file processing. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | |||
- | |||
- | ' Select A1. | ||
- | ScrollTo ActiveSheet.name, | ||
- | End With | ||
- | End With | ||
- | End Sub | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | ' Copies down all formulae on the SHEETNAME1 sheet. | ||
- | ' Does not change the formula to values. | ||
- | ' Does not calculate. | ||
- | ' This may run for a very long time. Go have a coffee. | ||
- | Sub M12020_Copy_SHEETNAME1_Formulae_Down() | ||
- | |||
- | Dim lastrow_SHEETNAME1 As Long | ||
- | |||
- | | ||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | | ||
- | | ||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | |||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | |||
- | |||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | ' | ||
- | lastrow_SHEETNAME1 = .Cells(Rows.Count, | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_SHEETNAME1 < 3 Then | ||
- | lastrow_SHEETNAME1 = 3 | ||
- | End If | ||
- | |||
- | |||
- | ' Copies formulae down. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | |||
- | |||
- | |||
- | ' Calculations. | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | |||
- | |||
- | ' Now copy and paste formula ranges as values to speed up the file processing. | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Select A1. | ||
- | ScrollTo ActiveSheet.name, | ||
- | End With | ||
- | End With | ||
- | End Sub | ||
- | |||
- | |||
- | ' Converts all formulae cells on the SHEETNAME1 sheet into values. | ||
- | ' Does not change row 2 of the SHEETNAME1 sheet. | ||
- | ' This may run for a very long time. Go have a coffee. | ||
- | Sub M12030_Convert_SHEETNAME1_Formulae_to_Values() | ||
- | |||
- | Dim lastrow_SHEETNAME1 As Long | ||
- | |||
- | |||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | | ||
- | | ||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | |||
- | With .Sheets(" | ||
- | |||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | |||
- | |||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | ' | ||
- | lastrow_SHEETNAME1 = .Cells(Rows.Count, | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_SHEETNAME1 < 3 Then | ||
- | lastrow_SHEETNAME1 = 3 | ||
- | End If | ||
- | |||
- | |||
- | ' Now copy and paste formula ranges as values to speed up the file processing. | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | |||
- | |||
- | ' Select A1. | ||
- | ScrollTo ActiveSheet.name, | ||
- | End With | ||
- | End With | ||
- | End Sub | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | ' Imports the Wxxxx file. | ||
- | Sub M13000_Import_Wxxxx() | ||
- | |||
- | Dim fileToOpen As Variant | ||
- | Dim count_Wxxxx As Double | ||
- | Dim count_InputFile As Double | ||
- | Dim lastrow_Wxxxx As Long | ||
- | Dim lastrow_InputFile As Long | ||
- | Dim my_from_column As Variant | ||
- | Dim my_to_column As Variant | ||
- | Dim fileToOpen_name As String | ||
- | Dim FileParts() As String | ||
- | | ||
- | |||
- | ' Initialize global vars. | ||
- | Call Z00000_Init | ||
- | |||
- | |||
- | ' Ask user. | ||
- | If ctrl_ask_before_running_subroutine = True Then | ||
- | If MsgBox(" | ||
- | End If | ||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | | ||
- | ' First clears out existing Wxxxx sheet, besides row 2 which is kept as it contains formulae. | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activates the sheet. | ||
- | .Activate | ||
- | |||
- | |||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_Wxxxx = .Cells(Rows.Count, | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_Wxxxx < 2 Then | ||
- | lastrow_Wxxxx = 2 | ||
- | End If | ||
- | | ||
- | ' Clear entire Wxxxx sheet, except for columns Y & Z which contains formulae. | ||
- | DeleteUnusedOnSheet (" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | | ||
- | ' Control to confirm there is currently no data in the sheet. | ||
- | If WorksheetFunction.CountA(.Range(" | ||
- | MsgBox "There is data still present in the Wxxxx sheet, these should be blank. Ensure they are empty before running this process" | ||
- | Exit Sub | ||
- | End If | ||
- | | ||
- | End With | ||
- | | ||
- | End With | ||
- | |||
- | |||
- | ' Ask user for a Wxxxx file to load. | ||
- | fileToOpen = Application.GetOpenFilename(" | ||
- | If fileToOpen = False Then | ||
- | MsgBox "No Wxxxx file selected. | ||
- | Exit Sub | ||
- | End If | ||
- | | ||
- | FileParts() = Split(fileToOpen, | ||
- | fileToOpen_name = FileParts(UBound(FileParts)) | ||
- | |||
- | |||
- | ' Start of copying columns across. | ||
- | With Workbooks.Open(fileToOpen) | ||
- | | ||
- | With .Sheets(1) | ||
- | |||
- | ' Activate the workbook. | ||
- | .Activate | ||
- | |||
- | |||
- | ' Control to check that the Wxxxx file is in the usual format. | ||
- | ' | ||
- | ' | ||
- | | ||
- | ' | ||
- | ' Close the file. | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | | ||
- | ' Control to check that the Wxxxx file is in the usual format. | ||
- | If WorksheetFunction.CountA(.Range(" | ||
- | Else | ||
- | If ctrl_close_erroneous_files = True Then | ||
- | ' Close the file. | ||
- | | ||
- | Workbooks(fileToOpen_name).Close | ||
- | Application.DisplayAlerts = True | ||
- | End If | ||
- | | ||
- | MsgBox "The Wxxxx file is not in the usual format, it may have been change since the code was written, please follow the procedure to manually copy the columns across" | ||
- | Exit Sub | ||
- | End If | ||
- | | ||
- | | ||
- | ' Determine how many rows in the input file. | ||
- | lastrow_InputFile = .Cells(Rows.Count, | ||
- | | ||
- | ' | ||
- | |||
- | |||
- | | ||
- | |||
- | ' Copy all columns from Wxxxx file into master sheet where column names match. | ||
- | For Each my_from_column In .Range(" | ||
- | For Each my_to_column In Workbooks(wb_name).Sheets(" | ||
- | If my_from_column = my_to_column Then | ||
- | .Range(Cells(2, | ||
- | End If | ||
- | Next my_to_column | ||
- | Next my_from_column | ||
- | |||
- | | ||
- | ' Counts the number of cells from the input file that should have been copied across. | ||
- | count_InputFile = WorksheetFunction.CountA(.Range(" | ||
- | |||
- | End With | ||
- | | ||
- | | ||
- | ' Close the file. | ||
- | Application.DisplayAlerts = False | ||
- | .Close | ||
- | Application.DisplayAlerts = True | ||
- | | ||
- | End With | ||
- | |||
- | |||
- | ' Counts the number of cells in the Wxxxx sheet that have been copied across. | ||
- | With Workbooks(wb_name) | ||
- | | ||
- | ' Activate the workbook. | ||
- | .Activate | ||
- | | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activate the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Get how many rows of data have been loaded into the sheet. | ||
- | lastrow_Wxxxx = .Cells(Rows.Count, | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_Wxxxx < 2 Then | ||
- | lastrow_Wxxxx = 2 | ||
- | End If | ||
- | | ||
- | | ||
- | ' Count how much data has been loaded into the Wxxxx sheet. | ||
- | count_Wxxxx = WorksheetFunction.CountA(.Range(" | ||
- | | ||
- | | ||
- | ' Select A1. | ||
- | ScrollTo ActiveSheet.name, | ||
- | | ||
- | End With | ||
- | | ||
- | End With | ||
- | |||
- | |||
- | ' Control to ensure that the number of cells copied across matches those in the originating file. | ||
- | If count_Wxxxx <> count_InputFile Then | ||
- | MsgBox "The number of cells copied from the Wxxxx file does not equal the number of cells copied to the 1042 rec. Please manually copy them across." | ||
- | Exit Sub | ||
- | End If | ||
- | |||
- | |||
- | |||
- | ' Add in formulae and sort the Wxxxx sheet. | ||
- | With Workbooks(wb_name) | ||
- | | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activates the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Determine the number of rows. | ||
- | lastrow_Wxxxx = .Cells(Rows.Count, | ||
- | ' Prevent line 2 being deleted - as this contains the formulae which need coping down later. | ||
- | If lastrow_Wxxxx < 2 Then | ||
- | lastrow_Wxxxx = 2 | ||
- | End If | ||
- | | ||
- | | ||
- | ' Resets formulae on " | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | .Range(" | ||
- | | ||
- | |||
- | ' | ||
- | With .Sort | ||
- | |||
- | ' | ||
- | With .SortFields | ||
- | .Clear | ||
- | .Add Key: | ||
- | End With | ||
- | | ||
- | .SetRange Range(" | ||
- | .Header = xlYes | ||
- | .MatchCase = False | ||
- | .Orientation = xlTopToBottom | ||
- | .SortMethod = xlPinYin | ||
- | .Apply | ||
- | | ||
- | End With | ||
- | |||
- | |||
- | ' Select A1. | ||
- | ScrollTo ActiveSheet.name, | ||
- | |||
- | End With | ||
- | End With | ||
- | |||
- | |||
- | |||
- | ' Clear all objects. | ||
- | Set my_from_column = Nothing | ||
- | Set my_to_column = Nothing | ||
- | | ||
- | End Sub | ||
- | |||
- | </ | ||
microsoft_excel/macro_full_example_program.1576238541.txt.gz · Last modified: 2020/07/15 09:30 (external edit)