Advertisement
Guest User

Untitled

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