Guest User

Untitled

a guest
Aug 30th, 2015
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 41.64 KB | None | 0 0
  1. Option Explicit
  2. Option Compare Text
  3.  
  4. '/ Workbooks
  5. Public WbSubsheet As Workbook '/ Contains all Lumin Wealth submitted Business
  6. Public WbAdviserReport As Workbook '/ Will Contain an aggregation of the subsheet and a submission report (by month) for each adviser
  7.  
  8. '/ Adviser Report worksheets
  9. Public WsAggregatedData As Worksheet '/ Will contain the aggregated subsheet data
  10. Public WsAdviserReport As Worksheet '/ Will contain the submissions report, reported by Adviser
  11. Public WsProviderReport As Worksheet '/ Will contain the submissions report, reported by Provider
  12. Public WsProductReport As Worksheet '/ Will contain the submissions report, reportrd by Type of Business
  13. Public WsChangedData As Worksheet '/ Record of Data CleanUp
  14.  
  15. '/ Subsheet Worksheets
  16. Public WsNewClient As Worksheet '/ 'New Client' Investments of Assets
  17. Public WsExistingClient As Worksheet '/ 'Existing Client' Investments of assets
  18. Public WsGroupSchemes As Worksheet '/ 'e.g. Corporate pension schemes and/or Auto Enrolment
  19. Public WsOther As Worksheet '/ Misc. bits and pieces
  20. Public WsMcOngoing As Worksheet '/ Martin's recurring product commissions e.g. insurance policies
  21. Public WsJhOngoing As Worksheet '/ Jon's recurring product commissions e.g. insurance policies
  22. Public WsAegonQuilterArc As Worksheet '/ Recurring fees from accounts with Aegon, Quilter and ARC
  23. Public WsAscentric As Worksheet '/ Recurring fees from accounts on Asccentric
  24.  
  25. '/ Data Arrays
  26. Public ArrAggregatedArrays As Variant '/ Holds all the sheet-Data Arrays
  27.  
  28. Public ArrAggregatedData As Variant '/ The data from all worksheets
  29.  
  30. Public ArrProviders As Variant '/ all providers found in the subsheet
  31. Public ArrAdvisers As Variant '/ all the advisers found in the subsheet
  32.  
  33. '/ Collections of names
  34. Public ColAllHeadings As Collection '/ All desired Column Headings from the subsheet
  35. Public ColMetrics As Collection '/ Metrics in the final report
  36. Public colAdviserNames As Collection '/ All Adviser names that MIGHT be in the Subsheet
  37.  
  38. '/ Constants, and variables that are only set once
  39. Public StrCurrentDate As String '/ The current Date for datestamping the saved report
  40. Public StrSavedReportFilename As String '/ The filename to save the report as
  41.  
  42. Public LngFinalCellRow As Long
  43. Public LngFinalCellColumn As Long
  44.  
  45. Public Const StrAdviserReportFilePath As String = "S:Lumin Admin DocsAdviser Submission Reports" '/ The path of the folder containing the Adviser Report
  46. Public Const StrSavedReportsFilePath As String = "S:Lumin Admin DocsAdviser Submission ReportsSaved Reports" '/ The path of the folder containing previous reports
  47. Public Const StrSubsheetFilePath As String = "S:Lumin Admin DocsSubsheet and Commission statements" '/ The path of the folder containing the Subsheet
  48.  
  49. Public Const StrAdviserReportFilename As String = "Adviser Submissions Report - v0.5.xlsm" '/ The filename of the Adviser Submissions Report
  50. Public Const StrSubsheetFilename As String = "Lumin Subsheet 2015.xlsm" '/ The filename of the Subsheet
  51.  
  52. Public Const Hyphen As String = " - "
  53.  
  54. Public varScreenUpdating As Boolean
  55. Public varEnableEvents As Boolean
  56. Public varCalculation As XlCalculation
  57.  
  58. Public Sub GenerateAdviserSubmissionReports()
  59.  
  60. StoreApplicationSettings
  61.  
  62. DisableApplicationSettings
  63.  
  64. '/======================================================================================================================================================
  65. '/ Author: Zak Armstrong
  66. '/ Date: 21/August/2015
  67. '/ Version: 0.3
  68. '/
  69. '/ Description: All Lumin Wealth Business is contained in the Subsheet. This macro produces adviser totals for business (assets and fees) in the previous year
  70. '/ (month by month breakdown) by aggregating the subsheet into one giant table and then assigning each piece of business to an adviser, a Month and a business type.
  71. '/ The report can then be easily configured for any desired outputs (E.G. by adviser, by provider, by type of business)
  72. '/======================================================================================================================================================
  73. '/======================================================================================================================================================
  74. InitialiseGlobalsBooksSheetsAndCollections
  75.  
  76. GetAllSheetDataIntoArrays
  77.  
  78. FilterSheetArrays
  79.  
  80. AggregateSheetData
  81.  
  82. CloseWorkbook WbSubsheet
  83.  
  84. PrintAggregatedData
  85.  
  86. CleanUpAggregatedData
  87.  
  88. RestoreApplicationSettings
  89.  
  90. End Sub
  91.  
  92. Public Sub InitialiseGlobalsBooksSheetsAndCollections()
  93.  
  94. Sheets(1).Activate
  95. LngFinalCellRow = Sheets(1).Rows.Count
  96. LngFinalCellColumn = Sheets(1).Columns.Count
  97.  
  98. '/ initialise public arrays
  99. ArrAggregatedData = Array()
  100. ArrAggregatedArrays = Array()
  101. ArrProviders = Array()
  102. ArrAdvisers = Array()
  103.  
  104. GetWorkbook StrAdviserReportFilename, StrAdviserReportFilePath
  105. Set WbAdviserReport = Workbooks(StrAdviserReportFilename)
  106.  
  107. GetWorkbook StrSubsheetFilename, StrSubsheetFilePath
  108. Set WbSubsheet = Workbooks(StrSubsheetFilename)
  109.  
  110. AssignWorksheets
  111.  
  112. InitialiseCollections
  113.  
  114. End Sub
  115.  
  116. Public Sub AssignWorksheets()
  117.  
  118. '/======================================================================================================================================================
  119. '/ Date: 21.08.2015
  120. '/======================================================================================================================================================
  121.  
  122. WbAdviserReport.Activate
  123.  
  124. Set WsAggregatedData = WbAdviserReport.Worksheets("Aggregated Subsheet Data")
  125. Set WsAdviserReport = WbAdviserReport.Worksheets("Adviser Submissions Report")
  126. Set WsProviderReport = WbAdviserReport.Worksheets("Provider Submissions Report")
  127. Set WsProductReport = WbAdviserReport.Worksheets("Product Submissions Report")
  128. Set WsChangedData = WbAdviserReport.Worksheets("Changed Data")
  129.  
  130. WbSubsheet.Activate
  131.  
  132. Set WsNewClient = WbSubsheet.Worksheets("New Client Investment")
  133. Set WsExistingClient = WbSubsheet.Worksheets("Existing Client Investment")
  134. Set WsGroupSchemes = WbSubsheet.Worksheets("Group Schemes")
  135. Set WsOther = WbSubsheet.Worksheets("Other")
  136. Set WsMcOngoing = WbSubsheet.Worksheets("MC Ongoing")
  137. Set WsJhOngoing = WbSubsheet.Worksheets("JH Ongoing")
  138. Set WsAegonQuilterArc = WbSubsheet.Worksheets("AG-QU-ARC")
  139. Set WsAscentric = WbSubsheet.Worksheets("Ascentric")
  140.  
  141. End Sub
  142.  
  143. Public Sub InitialiseCollections()
  144.  
  145. '/======================================================================================================================================================
  146. '/ Date: 21.08.2015
  147. '/======================================================================================================================================================
  148. Dim i As Long
  149. '/======================================================================================================================================================
  150.  
  151. Set ColAllHeadings = New Collection
  152. '/ N.B. this will be the order of headings in the aggregated sheet
  153.  
  154. ColAllHeadings.Add "Adviser"
  155.  
  156. ColAllHeadings.Add "First Name"
  157. ColAllHeadings.Add "Last Name"
  158. ColAllHeadings.Add "Account Name"
  159. ColAllHeadings.Add "Life Co"
  160. ColAllHeadings.Add "Date Submitted"
  161. ColAllHeadings.Add "Description"
  162.  
  163. ColAllHeadings.Add "Investment Amount"
  164. ColAllHeadings.Add "Money Received"
  165.  
  166. ColAllHeadings.Add "Total Monthly Premium"
  167. ColAllHeadings.Add "Single Premium"
  168.  
  169. ColAllHeadings.Add "Commission Due"
  170. ColAllHeadings.Add "Comm Paid - Checked To Bank"
  171. ColAllHeadings.Add "Date Received - Bank"
  172.  
  173. For i = 1 To 12
  174. ColAllHeadings.Add DateValue("01/" & Right("0" & i, 2) & "/2015")
  175. Next i
  176.  
  177.  
  178. Set ColMetrics = New Collection
  179. ColMetrics.Add "Investment Amount"
  180. ColMetrics.Add "Single Premium"
  181. ColMetrics.Add "Total Monthly Premium"
  182. ColMetrics.Add "Commission Due"
  183. ColMetrics.Add "Comm Paid - Checked To Bank"
  184. ColMetrics.Add "Recurring"
  185.  
  186.  
  187. Set colAdviserNames = New Collection
  188. colAdviserNames.Add "Martin Cotter", "Martin"
  189. colAdviserNames.Add "Jon Hussey", "Jon"
  190. colAdviserNames.Add "Micky Mahbubani", "Micky"
  191. colAdviserNames.Add "Jeremy Smith", "Jeremy"
  192. colAdviserNames.Add "Sarah Cotter", "Sarah"
  193. colAdviserNames.Add "John Cusins", "John"
  194.  
  195. End Sub
  196.  
  197. Private Sub GetAllSheetDataIntoArrays()
  198.  
  199. '/======================================================================================================================================================
  200. '/ Author: Zak Armstrong
  201. '/ Date: 28/August/2015
  202. '/
  203. '/ Description: Creates Arrays for each sheet, Calls sub to fill each with their sheet's data, collects arrays together in arrAggregatedArrys
  204. '/======================================================================================================================================================
  205. Dim arrNewClient As Variant
  206. arrNewClient = Array()
  207.  
  208. Dim arrExistingClient As Variant
  209. arrExistingClient = Array()
  210.  
  211. Dim arrGroupSchemes As Variant
  212. arrGroupSchemes = Array()
  213.  
  214. Dim arrOther As Variant
  215. arrOther = Array()
  216.  
  217. Dim arrMcOngoing As Variant
  218. arrMcOngoing = Array()
  219.  
  220. Dim arrJhOngoing As Variant
  221. arrJhOngoing = Array()
  222.  
  223. Dim arrAegonQuilterArc As Variant
  224. arrAegonQuilterArc = Array()
  225.  
  226. Dim arrAscentric As Variant
  227. arrAscentric = Array()
  228. '/======================================================================================================================================================
  229.  
  230. Dim strTopLeftCellIdentifier As String
  231. strTopLeftCellIdentifier = "Adviser"
  232.  
  233. PutSheetDataInArray WbSubsheet, WsNewClient, arrNewClient, strTopLeftCellIdentifier
  234. PutSheetDataInArray WbSubsheet, WsExistingClient, arrExistingClient, strTopLeftCellIdentifier
  235. PutSheetDataInArray WbSubsheet, WsGroupSchemes, arrGroupSchemes, strTopLeftCellIdentifier
  236. PutSheetDataInArray WbSubsheet, WsOther, arrOther, strTopLeftCellIdentifier
  237. PutSheetDataInArray WbSubsheet, WsMcOngoing, arrMcOngoing, strTopLeftCellIdentifier
  238. PutSheetDataInArray WbSubsheet, WsJhOngoing, arrJhOngoing, strTopLeftCellIdentifier
  239. PutSheetDataInArray WbSubsheet, WsAegonQuilterArc, arrAegonQuilterArc, strTopLeftCellIdentifier
  240.  
  241. strTopLeftCellIdentifier = "Account No"
  242. PutSheetDataInArray WbSubsheet, WsAscentric, arrAscentric, strTopLeftCellIdentifier
  243.  
  244. InsertAscentricLifeCoColumn arrAscentric
  245.  
  246. ReDim ArrAggregatedArrays(1 To 8)
  247. ArrAggregatedArrays(1) = arrNewClient
  248. ArrAggregatedArrays(2) = arrExistingClient
  249. ArrAggregatedArrays(3) = arrGroupSchemes
  250. ArrAggregatedArrays(4) = arrOther
  251. ArrAggregatedArrays(5) = arrMcOngoing
  252. ArrAggregatedArrays(6) = arrJhOngoing
  253. ArrAggregatedArrays(7) = arrAegonQuilterArc
  254. ArrAggregatedArrays(8) = arrAscentric
  255.  
  256. End Sub
  257.  
  258. Private Sub FilterSheetArrays()
  259.  
  260. Dim i As Long
  261. Dim LB1 As Long, UB1 As Long
  262.  
  263. AssignArrayBounds ArrAggregatedArrays, LB1, UB1
  264.  
  265. For i = LB1 To UB1
  266. FilterSheetArrayForColumns ArrAggregatedArrays(i)
  267. Next i
  268.  
  269. End Sub
  270.  
  271. Private Sub FilterSheetArrayForColumns(ByRef arrSource As Variant)
  272.  
  273. '/======================================================================================================================================================
  274. '/ Author: Zak Armstrong
  275. '/ Date: 12/August/2015
  276. '/
  277. '/ Description: Takes Sheet arrays, finds the columns from the colAllHeadings, recreates the array with just that data (and empty columns for the ones not found)
  278. '/======================================================================================================================================================
  279. Dim i As Long, j As Long, k As Long
  280.  
  281. Dim LB1 As Long, UB1 As Long
  282. Dim LB2 As Long, UB2 As Long
  283.  
  284. Dim arrTempArray As Variant
  285. arrTempArray = Array()
  286.  
  287. Dim arrHeadingsRow As Variant
  288. arrHeadingsRow = Array()
  289. '/======================================================================================================================================================
  290.  
  291. AssignArrayBounds arrSource, LB1, UB1, LB2, UB2
  292.  
  293. arrHeadingsRow = RowFrom2dArray(arrSource, 1)
  294.  
  295. arrHeadingsRow = ElementsToStrings1dArray(arrHeadingsRow)
  296.  
  297. ReDim arrTempArray(0 To UB1, 0 To ColAllHeadings.Count)
  298. arrTempArray(0, 0) = arrSource(0, 0)
  299.  
  300.  
  301. Dim lngDestinationColumn As Long
  302. Dim lngSourceColumn As Long
  303.  
  304. Dim varColumnPosition As Variant
  305.  
  306. Dim strHeading As String
  307.  
  308. For i = 1 To ColAllHeadings.Count
  309. strHeading = ColAllHeadings(i)
  310. varColumnPosition = IndexInArray1d(arrHeadingsRow, strHeading)
  311.  
  312. If IsError(varColumnPosition) _
  313. Then
  314. MissingDataHeadingsHandler arrSource, strHeading
  315. Else
  316. lngDestinationColumn = i
  317. lngSourceColumn = varColumnPosition
  318.  
  319. CopyArrayColumn2d arrSource, lngSourceColumn, arrTempArray, lngDestinationColumn
  320. End If
  321. Next i
  322.  
  323. arrSource = arrTempArray
  324.  
  325. End Sub
  326.  
  327. Public Sub MissingDataHeadingsHandler(ByRef arrCurrentArray As Variant, ByVal strHeading As String)
  328.  
  329. '/======================================================================================================================================================
  330. '/ Author: Zak Armstrong
  331. '/ Date: 13/August/2015
  332. '/
  333. '/ Description: Handle instances where a column heading can't be found. Reference against sheet-specific lists to see if the column should be there or not.
  334. '/======================================================================================================================================================
  335. Dim bErrorFound As Boolean
  336.  
  337. Dim colMissingSheetHeadings As Collection '/ For each sheet, contains the headings that shouldn't be there
  338.  
  339. Dim strException As String '/ holds string items from colMissingSheetHeadings
  340. Dim strErrorMessage As String
  341.  
  342. Dim i As Long
  343. Dim j As Long
  344. Dim k As Long
  345. '/======================================================================================================================================================
  346.  
  347. strErrorMessage = "Couldn't find Column Heading: " & arrCurrentArray(0, 0) & ": " & strHeading
  348. bErrorFound = True
  349.  
  350. Set colMissingSheetHeadings = New Collection
  351.  
  352. Select Case arrCurrentArray(0, 0) '/ Contains the name of the worksheet the data was taken from
  353.  
  354. Case Is = WsNewClient.Name
  355. InitialiseNewClientHeadingsExceptions colMissingSheetHeadings
  356.  
  357. Case Is = WsExistingClient.Name
  358. InitialiseExistingClientHeadingsExceptions colMissingSheetHeadings
  359.  
  360.  
  361. Case Is = WsGroupSchemes.Name
  362. InitialiseGroupSchemesHeadingsExceptions colMissingSheetHeadings
  363.  
  364.  
  365. Case Is = WsOther.Name
  366. InitialiseOtherHeadingsExceptions colMissingSheetHeadings
  367.  
  368.  
  369. Case Is = WsMcOngoing.Name
  370. InitialiseMcOngoingHeadingsExceptions colMissingSheetHeadings
  371.  
  372.  
  373. Case Is = WsJhOngoing.Name
  374. InitialiseJhOngoingHeadingsExceptions colMissingSheetHeadings
  375.  
  376.  
  377. Case Is = WsAegonQuilterArc.Name
  378. InitialiseAegonQuilterArcHeadingsExceptions colMissingSheetHeadings
  379.  
  380.  
  381. Case Is = WsAscentric.Name
  382. InitialiseAscentricHeadingsExceptions colMissingSheetHeadings
  383.  
  384. Case Else
  385. ErrorMessage strErrorMessage
  386.  
  387. End Select
  388.  
  389.  
  390. For i = 1 To colMissingSheetHeadings.Count
  391. strException = colMissingSheetHeadings(i)
  392. If strHeading = strException Then bErrorFound = False
  393. Next i
  394.  
  395. If bErrorFound = True Then ErrorMessage (strErrorMessage)
  396.  
  397. End Sub
  398.  
  399. Public Sub InitialiseNewClientHeadingsExceptions(ByRef colMissingSheetHeadings As Collection)
  400.  
  401. Dim i As Long
  402.  
  403. colMissingSheetHeadings.Add ("Total Monthly Premium")
  404. colMissingSheetHeadings.Add ("Single Premium")
  405. colMissingSheetHeadings.Add ("Account Name")
  406. colMissingSheetHeadings.Add ("Life Co")
  407. For i = 1 To 12
  408. colMissingSheetHeadings.Add (DateValue("01/" & Right("0" & i, 2) & "/" & Year(Date)))
  409. Next i
  410.  
  411. End Sub
  412.  
  413. Private Sub AggregateSheetData()
  414.  
  415. '/======================================================================================================================================================
  416. '/ Author: Zak Armstrong
  417. '/ Date: 13/August/2015
  418. '/
  419. '/ Description: For Each array, add the data to arrAggregatedData
  420. '/======================================================================================================================================================
  421. Dim i As Long, j As Long, k As Long
  422.  
  423. Dim rngTopLeftCell As Range
  424.  
  425. Dim lngCurrentRow As Long
  426.  
  427. Dim LB1 As Long, UB1 As Long
  428. Dim LB2 As Long, UB2 As Long
  429. '/======================================================================================================================================================
  430. ReDim ArrAggregatedData(1 To ColAllHeadings.Count, 1 To 1)
  431.  
  432. lngCurrentRow = 1
  433.  
  434. For i = 1 To ColAllHeadings.Count
  435. ArrAggregatedData(i, 1) = ColAllHeadings(i)
  436. Next i
  437.  
  438. '/ All arrays were created as 0 - X, 0 - Y, hence LB + 1 and LB + 2
  439. For i = LBound(ArrAggregatedArrays) To UBound(ArrAggregatedArrays)
  440.  
  441. AssignArrayBounds ArrAggregatedArrays(i), LB1, UB1, LB2, UB2
  442.  
  443. For j = LB1 + 2 To UB1
  444. lngCurrentRow = lngCurrentRow + 1
  445. ReDim Preserve ArrAggregatedData(1 To ColAllHeadings.Count, 1 To lngCurrentRow)
  446.  
  447. For k = LB2 + 1 To UB2
  448. ArrAggregatedData(k, lngCurrentRow) = ArrAggregatedArrays(i)(j, k)
  449. Next k
  450. Next j
  451. Next i
  452.  
  453. Transpose2dArray ArrAggregatedData
  454.  
  455. End Sub
  456.  
  457. Private Sub FilterSheetArrays()
  458.  
  459. Dim i As Long
  460. Dim LB1 As Long, UB1 As Long
  461.  
  462. AssignArrayBounds ArrAggregatedArrays, LB1, UB1
  463.  
  464. For i = LB1 To UB1
  465. FilterSheetArrayForColumns ArrAggregatedArrays(i)
  466. Next i
  467.  
  468. End Sub
  469.  
  470. Private Sub CleanUpAggregatedData()
  471.  
  472. '/======================================================================================================================================================
  473. '/ Author: Zak Armstrong
  474. '/ Date: 13/August/2015
  475. '/
  476. '/ Description: Clean up the aggregated data table (converting shortened names to full names, removing in-sheet totals, replacing "N/A" etc.)
  477. '/ Makes a record of all changes (with the row for context) in the "Changed Data" sheet.
  478. '/======================================================================================================================================================
  479. Dim lngHeaderEndColumn As Long
  480.  
  481. Dim LB1 As Long, UB1 As Long
  482. Dim LB2 As Long, UB2 As Long
  483.  
  484. Dim arrChangedData As Variant
  485. arrChangedData = Array()
  486. '/======================================================================================================================================================
  487.  
  488. CreateHeadingChangedData arrChangedData, lngHeaderEndColumn
  489.  
  490. AssignRangeBoundsOfData WsAggregatedData.Cells(1, 1), LB1, UB1, LB2, UB2
  491.  
  492. RemoveUnwantedData arrChangedData, lngHeaderEndColumn, LB1, UB1, LB2, UB2
  493.  
  494. Transpose2dArray arrChangedData
  495.  
  496. Print2dArrayToSheet WbAdviserReport, WsChangedData, arrChangedData, WsChangedData.Cells(1, 1)
  497.  
  498. AssignRangeBoundsOfData WsAggregatedData.Cells(1, 1), LB1, UB1, LB2, UB2
  499.  
  500. ChangeAdviserNames lngHeaderEndColumn, LB1, UB1, LB2, UB2
  501.  
  502. End Sub
  503.  
  504. Public Sub CreateHeadingChangedData(ByRef arrChangedData As Variant, ByRef lngHeaderEndColumn As Long)
  505.  
  506. Dim i As Long
  507.  
  508. ReDim arrChangedData(1 To ColAllHeadings.Count + 4, 1 To 1)
  509.  
  510. arrChangedData(1, 1) = "Trigger Value"
  511. arrChangedData(2, 1) = "Row"
  512. arrChangedData(3, 1) = "Action"
  513. lngHeaderEndColumn = 3 + 1
  514.  
  515. For i = 1 To ColAllHeadings.Count
  516. arrChangedData(lngHeaderEndColumn + i, 1) = ColAllHeadings(i)
  517. Next i
  518.  
  519. End Sub
  520.  
  521. Public Sub RemoveUnwantedData(ByRef arrChangedData As Variant, ByRef lngHeaderEndColumn As Long, ByRef LB1 As Long, ByRef UB1 As Long, ByRef LB2 As Long, ByRef UB2 As Long)
  522.  
  523. Dim rngHolder As Range
  524. Dim i As Long, j As Long
  525.  
  526. WbAdviserReport.Activate
  527. WsAggregatedData.Activate
  528.  
  529. For i = UB1 To LB1 + 1 Step -1
  530.  
  531. Set rngHolder = Cells(i, LB2)
  532. If rngHolder.Text = "Total" Then RemoveRow arrChangedData, lngHeaderEndColumn, rngHolder, LB2, UB2
  533.  
  534. '/ Numeric Columns: (1) + 5 (Date Submitted) (1) + (7 - 25) (Inv. amount, premiums, commissions, Jan 2015 - Dec 2015)
  535. Set rngHolder = Cells(i, LB2 + 5)
  536. If Not (IsNumeric(rngHolder.Value) Or IsDate(rngHolder.Value)) Then RemoveCellContents arrChangedData, lngHeaderEndColumn, rngHolder, LB2, UB2
  537.  
  538. For j = 7 To 25
  539. Set rngHolder = Cells(i, LB2 + j)
  540. If Not (IsNumeric(rngHolder.Value) Or IsDate(rngHolder.Value)) Then RemoveCellContents arrChangedData, lngHeaderEndColumn, rngHolder, LB2, UB2
  541. Next j
  542.  
  543. Next i
  544.  
  545. End Sub
  546.  
  547. Public Sub RemoveCellContents(ByRef arrChangedData As Variant, ByVal lngHeaderEndColumn As Long, ByRef rngTargetCell As Range, ByVal lngFirstColumn As Long, ByVal lngFinalColumn As Long)
  548.  
  549. Dim lngCurrentRow As Long
  550. Dim lngFinalRow As Long
  551.  
  552. Dim lngRowLength As Long
  553. lngRowLength = lngFinalColumn - lngFirstColumn + 1
  554.  
  555. Dim rngTargetRow As Range
  556.  
  557. Dim i As Long
  558.  
  559. Dim arrTemp() As Variant
  560. ReDim arrTemp(1 To lngRowLength) As Variant
  561.  
  562. lngCurrentRow = rngTargetCell.Row
  563. For i = lngFirstColumn To lngFinalColumn
  564. arrTemp(i) = WsAggregatedData.Cells(lngCurrentRow, i).Value
  565. Next i
  566.  
  567. Dim LB1 As Long, UB1 As Long
  568. Dim LB2 As Long, UB2 As Long
  569.  
  570. AssignArrayBounds arrChangedData, LB1, UB1, LB2, UB2
  571. ReDim Preserve arrChangedData(LB1 To UB1, LB2 To UB2 + 1)
  572.  
  573. For i = 1 To lngRowLength
  574. arrChangedData(lngHeaderEndColumn + i, UB2 + 1) = arrTemp(i)
  575. Next i
  576.  
  577. arrChangedData(1, UB2 + 1) = rngTargetCell.Value
  578. arrChangedData(2, UB2 + 1) = "Row: " & rngTargetCell.Row
  579. arrChangedData(3, UB2 + 1) = "Cleared Contents"
  580.  
  581. rngTargetCell.ClearContents
  582.  
  583. End Sub
  584.  
  585. Public Sub RemoveRow(ByRef arrChangedData As Variant, ByVal lngHeaderEndColumn As Long, ByRef rngTargetCell As Range, ByVal lngFirstColumn As Long, ByVal lngFinalColumn As Long)
  586.  
  587. Dim lngCurrentRow As Long
  588. Dim lngFinalRow As Long
  589.  
  590. Dim lngRowLength As Long
  591. lngRowLength = lngFinalColumn - lngFirstColumn + 1
  592.  
  593. Dim rngTargetRow As Range
  594.  
  595. Dim i As Long
  596.  
  597. Dim arrTemp() As Variant
  598. ReDim arrTemp(1 To lngRowLength) As Variant
  599.  
  600. lngCurrentRow = rngTargetCell.Row
  601. For i = lngFirstColumn To lngFinalColumn
  602. arrTemp(i) = WsAggregatedData.Cells(lngCurrentRow, i).Value
  603. Next i
  604.  
  605. Dim LB1 As Long, UB1 As Long
  606. Dim LB2 As Long, UB2 As Long
  607.  
  608. AssignArrayBounds arrChangedData, LB1, UB1, LB2, UB2
  609. ReDim Preserve arrChangedData(LB1 To UB1, LB2 To UB2 + 1)
  610.  
  611. For i = 1 To lngRowLength
  612. arrChangedData(lngHeaderEndColumn + i, UB2 + 1) = arrTemp(i)
  613. Next i
  614.  
  615. arrChangedData(1, UB2 + 1) = rngTargetCell.Value
  616. arrChangedData(2, UB2 + 1) = "Row: " & rngTargetCell.Row
  617. arrChangedData(3, UB2 + 1) = "Deleted Row"
  618.  
  619. Rows(lngCurrentRow).Delete
  620.  
  621. End Sub
  622.  
  623. Public Sub ChangeAdviserNames(ByRef lngHeaderEndColumn As Long, ByRef LB1 As Long, ByRef UB1 As Long, ByRef LB2 As Long, ByRef UB2 As Long)
  624.  
  625. WbAdviserReport.Activate
  626. WsAggregatedData.Activate
  627.  
  628. Dim rngHolder As Range
  629.  
  630. Dim i As Long, j As Long
  631.  
  632. Dim bError As Boolean
  633.  
  634. Dim strErrorMessage As String
  635.  
  636. For i = UB1 To LB1 + 1 Step -1
  637.  
  638. Set rngHolder = Cells(i, LB2)
  639.  
  640. Select Case rngHolder.Text
  641.  
  642. Case Is = "Jon"
  643. rngHolder.Value = colAdviserNames.Item(rngHolder.Text)
  644.  
  645. Case Is = "Martin"
  646. rngHolder.Value = colAdviserNames.Item(rngHolder.Text)
  647.  
  648. Case Is = "Micky"
  649. rngHolder.Value = colAdviserNames.Item(rngHolder.Text)
  650.  
  651. Case Is = "Jeremy"
  652. rngHolder.Value = colAdviserNames.Item(rngHolder.Text)
  653.  
  654. Case Is = "John"
  655. rngHolder.Value = colAdviserNames.Item(rngHolder.Text)
  656.  
  657. Case Is = "Sarah"
  658. rngHolder.Value = colAdviserNames.Item(rngHolder.Text)
  659.  
  660. Case Else
  661. bError = True
  662.  
  663. For j = 1 To colAdviserNames.Count
  664. If rngHolder.Text = colAdviserNames(j) Then bError = False
  665. Next j
  666.  
  667. If bError _
  668. Then
  669. strErrorMessage = "Unidentified Adviser - Row: " & i & "Text: " & rngHolder.Text
  670. ErrorMessage (strErrorMessage)
  671. End If
  672.  
  673. End Select
  674.  
  675. Next i
  676.  
  677. End Sub
  678.  
  679. Option Explicit
  680. Option Compare Text
  681.  
  682. Public Sub GetWorkbook(ByVal strFilename As String, ByVal strFilePath As String)
  683.  
  684. Dim bWbIsOpen As Boolean
  685.  
  686. bWbIsOpen = WorkbookIsOpen(strFilename)
  687. If Not bWbIsOpen Then Workbooks.Open strFilePath & strFilename
  688.  
  689. End Sub
  690.  
  691. Public Function WorkbookIsOpen(ByVal strTargetName As String) As Boolean
  692.  
  693. Dim wbTest As Workbook
  694.  
  695. On Error Resume Next
  696.  
  697. Set wbTest = Workbooks(strTargetName)
  698.  
  699. WorkbookIsOpen = (wbTest.Name = strTargetName)
  700.  
  701. On Error GoTo 0
  702.  
  703. End Function
  704.  
  705. Public Sub PutSheetDataInArray(ByRef wbCurrent As Workbook, ByRef wsCurrent As Worksheet, ByRef arrCurrentArray As Variant, Optional ByVal strTopLeftCellIdentifier As Variant, _
  706. Optional ByVal lngStartRow As Long = 1, Optional ByVal lngEndRow As Variant, _
  707. Optional ByVal lngStartColumn As Long = 1, Optional ByVal lngEndColumn As Variant)
  708. '/======================================================================================================================================================
  709. Dim i As Long, j As Long, k As Long
  710.  
  711. Dim rngTopLeftCell As Range
  712. Dim rngSearchRange As Range
  713.  
  714. Dim strErrorMessage As String
  715.  
  716. Dim arrHiddenColumns As Variant
  717. arrHiddenColumns = Array()
  718.  
  719. Dim arrHiddenRows As Variant
  720. arrHiddenRows = Array()
  721.  
  722. Dim LB1 As Long, UB1 As Long
  723. Dim LB2 As Long, UB2 As Long
  724. '/======================================================================================================================================================
  725. wbCurrent.Activate
  726. wsCurrent.Activate
  727.  
  728. If IsMissing(strTopLeftCellIdentifier) _
  729. Then
  730. Set rngTopLeftCell = Cells(1, 1)
  731. ElseIf TypeName(strTopLeftCellIdentifier) = "String" _
  732. Then
  733. If IsMissing(lngEndRow) Then lngEndRow = wsCurrent.Rows.Count
  734. If IsMissing(lngEndColumn) Then lngEndColumn = wsCurrent.Columns.Count
  735.  
  736. Set rngSearchRange = wsCurrent.Range(Cells(lngStartRow, lngStartColumn), Cells(lngEndRow, lngEndColumn))
  737. Set rngTopLeftCell = CellContainingStringInRange(rngSearchRange, strTopLeftCellIdentifier)
  738. Else
  739. strErrorMessage = "strTopLeftCellIdentifier must be a string, not a " & TypeName(strTopLeftCellIdentifier)
  740. ErrorMessage (strErrorMessage)
  741. End If
  742.  
  743.  
  744. LB1 = rngTopLeftCell.Row
  745. LB2 = rngTopLeftCell.Column
  746. AssignRangeBoundsOfData rngTopLeftCell, UB1:=UB1, UB2:=UB2
  747.  
  748. RecordHiddenRowsAndUnhide arrHiddenRows, LB1, UB1
  749. RecordHiddenColumnsAndUnhide arrHiddenColumns, LB2, UB2
  750.  
  751. WriteRangeToArrayIteratively wsCurrent, arrCurrentArray, LB1, UB1, LB2, UB2
  752.  
  753. HideRows arrHiddenRows
  754. HideColumns arrHiddenColumns
  755.  
  756. End Sub
  757.  
  758. Public Function CellContainingStringInRange(ByRef rngSearch As Range, ByVal strSearch As String) As Range
  759.  
  760. Dim strErrorMessage As String
  761.  
  762. Set CellContainingStringInRange = rngSearch.Find(strSearch, LookIn:=xlValues)
  763.  
  764. If CellContainingStringInRange Is Nothing _
  765. Then
  766. strErrorMessage = "Couldn't find cell """ & strSearch & """ in " & rngSearch.Worksheet.Name
  767. ErrorMessage (strErrorMessage)
  768. End If
  769.  
  770. End Function
  771.  
  772. Public Sub RecordHiddenRowsAndUnhide(ByRef arrHiddenRows As Variant, ByVal LB1 As Long, ByVal UB1 As Long)
  773.  
  774. Dim i As Long
  775.  
  776. Dim lngCounter As Long
  777.  
  778. For i = LB1 To UB1
  779. If Rows(i).EntireRow.Hidden _
  780. Then
  781. lngCounter = lngCounter + 1
  782. ReDim Preserve arrHiddenRows(1 To lngCounter)
  783. arrHiddenRows(lngCounter) = i
  784. Rows(i).Hidden = False
  785. End If
  786. Next i
  787.  
  788. End Sub
  789.  
  790. Public Sub RecordHiddenColumnsAndUnhide(ByRef arrHiddenColumns As Variant, ByVal LB2 As Long, ByVal UB2 As Long)
  791.  
  792. Dim i As Long
  793.  
  794. Dim lngCounter As Long
  795.  
  796. For i = LB2 To UB2
  797. If Columns(i).EntireRow.Hidden _
  798. Then
  799. lngCounter = lngCounter + 1
  800. ReDim Preserve arrHiddenColumns(1 To lngCounter)
  801. arrHiddenColumns(lngCounter) = i
  802. Columns(i).Hidden = False
  803. End If
  804. Next i
  805.  
  806. End Sub
  807.  
  808. Public Sub HideRows(ByRef arrHiddenRows As Variant)
  809. Dim i As Long
  810.  
  811. For i = LBound(arrHiddenRows) To UBound(arrHiddenRows)
  812. Rows(i).EntireRow.Hidden = True
  813. Next i
  814.  
  815. End Sub
  816.  
  817. Public Sub HideColumns(ByRef arrHiddenColumns As Variant)
  818. Dim i As Long
  819.  
  820. For i = LBound(arrHiddenColumns) To UBound(arrHiddenColumns)
  821. Columns(i).EntireRow.Hidden = True
  822. Next i
  823.  
  824. End Sub
  825.  
  826. Public Sub AssignRangeBoundsOfData(ByRef rngCell As Range, Optional ByRef LB1 As Variant, Optional ByRef UB1 As Variant, Optional ByRef LB2 As Variant, Optional ByRef UB2 As Variant)
  827.  
  828. Dim wbCurrent As Workbook
  829. Dim wsCurrent As Worksheet
  830.  
  831. AssignCurrentBookAndSheet wbCurrent, wsCurrent
  832.  
  833. Dim wsRngCell As Worksheet
  834. Dim wbRngCell As Workbook
  835.  
  836. AssignRangeBookAndSheet rngCell, wbRngCell, wsRngCell
  837.  
  838. wbRngCell.Activate
  839. wsRngCell.Activate
  840.  
  841. Dim rngCurrentRegion As Range
  842. Set rngCurrentRegion = rngCell.CurrentRegion
  843.  
  844. If Not IsMissing(LB1) Then LB1 = rngCurrentRegion.Row
  845. If Not IsMissing(LB2) Then LB2 = rngCurrentRegion.Column
  846.  
  847. If Not IsMissing(UB1) Then UB1 = rngCurrentRegion.Row + rngCurrentRegion.Rows.Count - 1
  848. If Not IsMissing(UB2) Then UB2 = rngCurrentRegion.Column + rngCurrentRegion.Columns.Count - 1
  849.  
  850. wbCurrent.Activate
  851. wsCurrent.Activate
  852.  
  853. End Sub
  854.  
  855. Public Sub CopyArrayContents5d(ByRef arrSource As Variant, ByRef arrDestination As Variant)
  856.  
  857. Dim LB1 As Long, UB1 As Long
  858. Dim LB2 As Long, UB2 As Long
  859. Dim LB3 As Long, UB3 As Long
  860. Dim LB4 As Long, UB4 As Long
  861. Dim LB5 As Long, UB5 As Long
  862.  
  863. Dim i As Long, j As Long, k As Long
  864. Dim l As Long, m As Long
  865.  
  866. AssignArrayBounds arrSource, LB1, UB1, LB2, UB2, LB3, UB3, LB4, UB4, LB5, UB5
  867.  
  868. Erase arrDestination
  869. ReDim arrDestination(LB1 To UB1, LB2 To UB2, LB3 To UB3, LB4 To UB4, LB5 To UB5)
  870.  
  871. For i = LB1 To UB1
  872. For j = LB2 To UB2
  873. For k = LB3 To UB3
  874. For l = LB4 To UB4
  875. For m = LB5 To UB5
  876. arrDestination(i, j, k, l, m) = arrSource(i, j, k, l, m)
  877. Next m
  878. Next l
  879. Next k
  880. Next j
  881. Next i
  882.  
  883. End Sub
  884.  
  885. Public Sub CopyArrayContents4d(ByRef arrSource As Variant, ByRef arrDestination As Variant)
  886.  
  887. Dim LB1 As Long, UB1 As Long
  888. Dim LB2 As Long, UB2 As Long
  889. Dim LB3 As Long, UB3 As Long
  890. Dim LB4 As Long, UB4 As Long
  891.  
  892. Dim i As Long, j As Long, k As Long
  893. Dim l As Long
  894.  
  895. AssignArrayBounds arrSource, LB1, UB1, LB2, UB2, LB3, UB3, LB4, UB4
  896.  
  897. Erase arrDestination
  898. ReDim arrDestination(LB1 To UB1, LB2 To UB2, LB3 To UB3, LB4 To UB4)
  899.  
  900. For i = LB1 To UB1
  901. For j = LB2 To UB2
  902. For k = LB3 To UB3
  903. For l = LB4 To UB4
  904. arrDestination(i, j, k, l) = arrSource(i, j, k, l)
  905. Next l
  906. Next k
  907. Next j
  908. Next i
  909.  
  910. End Sub
  911.  
  912. Public Sub CopyArrayContents3d(ByRef arrSource As Variant, ByRef arrDestination As Variant)
  913.  
  914. Dim LB1 As Long, UB1 As Long
  915. Dim LB2 As Long, UB2 As Long
  916. Dim LB3 As Long, UB3 As Long
  917.  
  918. Dim i As Long, j As Long, k As Long
  919.  
  920. AssignArrayBounds arrSource, LB1, UB1, LB2, UB2, LB3, UB3
  921.  
  922. Erase arrDestination
  923. ReDim arrDestination(LB1 To UB1, LB2 To UB2, LB3 To UB3)
  924.  
  925. For i = LB1 To UB1
  926. For j = LB2 To UB2
  927. For k = LB3 To UB3
  928. arrDestination(i, j, k) = arrSource(i, j, k)
  929. Next k
  930. Next j
  931. Next i
  932.  
  933. End Sub
  934.  
  935. Public Sub CopyArrayContents2d(ByRef arrSource As Variant, ByRef arrDestination As Variant)
  936.  
  937. Dim LB1 As Long, UB1 As Long
  938. Dim LB2 As Long, UB2 As Long
  939.  
  940. Dim i As Long, j As Long
  941.  
  942. AssignArrayBounds arrSource, LB1, UB1, LB2, UB2
  943.  
  944. Erase arrDestination
  945. ReDim arrDestination(LB1 To UB1, LB2 To UB2)
  946.  
  947. For i = LB1 To UB1
  948. For j = LB2 To UB2
  949. arrDestination(i, j) = arrSource(i, j)
  950. Next j
  951. Next i
  952.  
  953. End Sub
  954.  
  955. Public Sub CopyArrayContents1d(ByRef arrSource As Variant, ByRef arrDestination As Variant)
  956.  
  957. Dim LB1 As Long, UB1 As Long
  958.  
  959. Dim i As Long
  960.  
  961. AssignArrayBounds arrSource, LB1, UB1
  962.  
  963. Erase arrDestination
  964. ReDim arrDestination(LB1 To UB1)
  965.  
  966. For i = LB1 To UB1
  967. arrDestination(i) = arrSource(i)
  968. Next i
  969.  
  970. End Sub
  971.  
  972. Public Sub AssignArrayBounds(ByRef arrCurrentArray As Variant, _
  973. Optional ByRef LB1 As Variant, Optional ByRef UB1 As Variant, _
  974. Optional ByRef LB2 As Variant, Optional ByRef UB2 As Variant, _
  975. Optional ByRef LB3 As Variant, Optional ByRef UB3 As Variant, _
  976. Optional ByRef LB4 As Variant, Optional ByRef UB4 As Variant, _
  977. Optional ByRef LB5 As Variant, Optional ByRef UB5 As Variant)
  978.  
  979. If Not IsMissing(LB1) Then LB1 = LBound(arrCurrentArray, 1)
  980. If Not IsMissing(UB1) Then UB1 = UBound(arrCurrentArray, 1)
  981. If Not IsMissing(LB2) Then LB2 = LBound(arrCurrentArray, 2)
  982. If Not IsMissing(UB2) Then UB2 = UBound(arrCurrentArray, 2)
  983. If Not IsMissing(LB3) Then LB3 = LBound(arrCurrentArray, 3)
  984. If Not IsMissing(UB3) Then UB3 = UBound(arrCurrentArray, 3)
  985. If Not IsMissing(LB4) Then LB4 = LBound(arrCurrentArray, 4)
  986. If Not IsMissing(UB4) Then UB4 = UBound(arrCurrentArray, 4)
  987. If Not IsMissing(LB5) Then LB5 = LBound(arrCurrentArray, 5)
  988. If Not IsMissing(UB5) Then UB5 = UBound(arrCurrentArray, 5)
  989.  
  990. End Sub
  991.  
  992. Public Sub Transpose2dArray(ByRef arrCurrentArray As Variant)
  993.  
  994. Dim LB1 As Long, UB1 As Long
  995. Dim LB2 As Long, UB2 As Long
  996.  
  997. Dim i As Long, j As Long
  998.  
  999. AssignArrayBounds arrCurrentArray, LB1, UB1, LB2, UB2
  1000.  
  1001. Dim arrTransposedArray() As Variant
  1002. ReDim arrTransposedArray(LB2 To UB2, LB1 To UB1)
  1003.  
  1004. For i = LB1 To UB1
  1005. For j = LB2 To UB2
  1006. arrTransposedArray(j, i) = arrCurrentArray(i, j)
  1007. Next j
  1008. Next i
  1009.  
  1010. Erase arrCurrentArray
  1011. ReDim arrCurrentArray(LB2 To UB2, LB1 To UB1)
  1012.  
  1013. arrCurrentArray = arrTransposedArray
  1014.  
  1015. End Sub
  1016.  
  1017. Public Sub Print2dArrayToSheet(ByRef wbTarget As Workbook, ByRef wsTarget As Worksheet, ByRef arrData As Variant, ByRef rngStartCell As Range)
  1018.  
  1019. Dim LB1 As Long, UB1 As Long
  1020. Dim LB2 As Long, UB2 As Long
  1021.  
  1022. Dim rngTableRange As Range
  1023.  
  1024. wbTarget.Activate
  1025. wsTarget.Activate
  1026.  
  1027. AssignArrayBounds arrData, LB1, UB1, LB2, UB2
  1028. Set rngTableRange = Range(rngStartCell, Cells(rngStartCell.Row + UB1 - LB1, rngStartCell.Column + UB2 - LB2))
  1029. rngTableRange = arrData
  1030.  
  1031. End Sub
  1032.  
  1033. Public Sub CopyArrayColumn2d(ByRef arrSource As Variant, ByVal lngSourceColumn As Long, ByRef arrTarget As Variant, ByVal lngTargetColumn As Long)
  1034.  
  1035. Dim i As Long, j As Long, k As Long
  1036.  
  1037. Dim LB1 As Long, UB1 As Long
  1038.  
  1039. AssignArrayBounds arrSource, LB1, UB1
  1040.  
  1041. For i = LB1 To UB1
  1042. arrTarget(i, lngTargetColumn) = arrSource(i, lngSourceColumn)
  1043. Next i
  1044.  
  1045. End Sub
  1046.  
  1047. Public Function RowFrom2dArray(ByRef arrSource As Variant, ByVal lngRow As Long) As Variant
  1048.  
  1049. Dim LB2 As Long, UB2 As Long
  1050. Dim i As Long
  1051.  
  1052. Dim arrRow As Variant
  1053. arrRow = Array()
  1054.  
  1055. AssignArrayBounds arrSource, LB2:=LB2, UB2:=UB2
  1056.  
  1057. ReDim arrRow(LB2 To UB2)
  1058.  
  1059. For i = LB2 To UB2
  1060. arrRow(i) = arrSource(lngRow, i)
  1061. Next i
  1062.  
  1063. RowFrom2dArray = arrRow
  1064.  
  1065. End Function
  1066.  
  1067. Public Function IndexInArray1d(ByRef arrSource As Variant, ByVal varSearch As Variant) As Variant
  1068.  
  1069. Dim LB1 As Long, UB1 As Long
  1070.  
  1071. Dim bMatchFound As Boolean
  1072.  
  1073. Dim i As Long
  1074.  
  1075. AssignArrayBounds arrSource, LB1, UB1
  1076. bMatchFound = False
  1077.  
  1078. i = LB1
  1079. Do While i <= UB1 And bMatchFound = False
  1080. If arrSource(i) = varSearch _
  1081. Then
  1082. bMatchFound = True
  1083. IndexInArray1d = i
  1084. End If
  1085. i = i + 1
  1086. Loop
  1087.  
  1088. If Not bMatchFound Then IndexInArray1d = CVErr(xlErrValue)
  1089.  
  1090. End Function
  1091.  
  1092. Public Sub AssignCurrentBookAndSheet(ByRef wbCurrent As Workbook, ByRef wsCurrent As Worksheet)
  1093.  
  1094. Set wbCurrent = ThisWorkbook
  1095. Set wsCurrent = ActiveSheet
  1096.  
  1097. End Sub
  1098.  
  1099. Public Sub AssignRangeBookAndSheet(ByRef rngTarget As Range, ByRef wbTarget As Workbook, ByRef wsTarget As Worksheet)
  1100.  
  1101. Set wbTarget = rngTarget.Worksheet.Parent
  1102. Set wsTarget = rngTarget.Worksheet
  1103.  
  1104. End Sub
  1105.  
  1106. Public Sub WriteRangeToArrayIteratively(ByRef wsCurrent As Worksheet, arrCurrentArray As Variant, ByVal LB1 As Long, ByVal UB1 As Long, ByVal LB2 As Long, ByVal UB2 As Long)
  1107. Dim i As Long, j As Long
  1108.  
  1109. wsCurrent.Activate
  1110.  
  1111. ReDim arrCurrentArray(0 To UB1 - LB1 + 1, 0 To UB2 - LB2 + 1)
  1112. arrCurrentArray(0, 0) = wsCurrent.Name
  1113.  
  1114. For i = LB1 To UB1
  1115. For j = LB2 To UB2
  1116. arrCurrentArray(i - LB1 + 1, j - LB2 + 1) = wsCurrent.Cells(i, j)
  1117. Next j
  1118. Next i
  1119.  
  1120. End Sub
  1121.  
  1122. Public Function ElementsToStrings1dArray(ByRef arrSource As Variant) As Variant
  1123.  
  1124. Dim i As Long
  1125. Dim arrRow As Variant
  1126. arrRow = arrSource
  1127.  
  1128. For i = LBound(arrSource) To UBound(arrSource)
  1129. arrRow(i) = CStr(arrRow(i))
  1130. Next i
  1131.  
  1132. ElementsToStrings1dArray = arrRow
  1133.  
  1134. End Function
  1135.  
  1136. Public Sub ErrorMessage(ByVal strErrorMessage As String)
  1137.  
  1138. MsgBox strErrorMessage
  1139. Debug.Print strErrorMessage
  1140. RestoreApplicationSettings
  1141. Stop
  1142.  
  1143. End Sub
  1144.  
  1145. Public Sub StoreApplicationSettings()
  1146.  
  1147. varScreenUpdating = Application.ScreenUpdating
  1148. varEnableEvents = Application.EnableEvents
  1149. varCalculation = Application.Calculation
  1150.  
  1151. End Sub
  1152.  
  1153. Public Sub DisableApplicationSettings()
  1154.  
  1155. Application.ScreenUpdating = False
  1156. Application.EnableEvents = False
  1157. Application.Calculation = xlCalculationManual
  1158.  
  1159. End Sub
  1160.  
  1161. Public Sub RestoreApplicationSettings()
  1162.  
  1163. Application.ScreenUpdating = varScreenUpdating
  1164. Application.EnableEvents = varEnableEvents
  1165. Application.Calculation = varCalculation
  1166.  
  1167. End Sub
  1168.  
  1169. Public Sub CloseWorkbook(ByRef wbTarget As Workbook)
  1170.  
  1171. Application.DisplayAlerts = False
  1172. wbTarget.Close
  1173. Application.DisplayAlerts = True
  1174.  
  1175. End Sub
Advertisement
Add Comment
Please, Sign In to add comment