├── Excel - Date Formating.docx ├── Excel - Date Function Definitions.docx ├── Excel - String Functions.docx ├── Mod_Autofilter.bas ├── Mod_Cells.bas ├── Mod_Charts.bas ├── Mod_Column.bas ├── Mod_Date.bas ├── Mod_Files.bas ├── Mod_Main.bas ├── Mod_Outlook.bas ├── Mod_Pivot.bas ├── Mod_PowerPoint.bas ├── Mod_Queries.bas ├── Mod_Row.bas ├── Mod_Search.bas ├── Mod_String.bas ├── Mod_Workbook.bas ├── Outlook - Email from Excel.docx ├── README.md └── VBA_Code_Library.xlsm /Excel - Date Formating.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/carvetighter/VBA-Code-Library/041882b8f9d97940f21019fdd4da822162678267/Excel - Date Formating.docx -------------------------------------------------------------------------------- /Excel - Date Function Definitions.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/carvetighter/VBA-Code-Library/041882b8f9d97940f21019fdd4da822162678267/Excel - Date Function Definitions.docx -------------------------------------------------------------------------------- /Excel - String Functions.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/carvetighter/VBA-Code-Library/041882b8f9d97940f21019fdd4da822162678267/Excel - String Functions.docx -------------------------------------------------------------------------------- /Mod_Autofilter.bas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/carvetighter/VBA-Code-Library/041882b8f9d97940f21019fdd4da822162678267/Mod_Autofilter.bas -------------------------------------------------------------------------------- /Mod_Cells.bas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/carvetighter/VBA-Code-Library/041882b8f9d97940f21019fdd4da822162678267/Mod_Cells.bas -------------------------------------------------------------------------------- /Mod_Charts.bas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/carvetighter/VBA-Code-Library/041882b8f9d97940f21019fdd4da822162678267/Mod_Charts.bas -------------------------------------------------------------------------------- /Mod_Column.bas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/carvetighter/VBA-Code-Library/041882b8f9d97940f21019fdd4da822162678267/Mod_Column.bas -------------------------------------------------------------------------------- /Mod_Date.bas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/carvetighter/VBA-Code-Library/041882b8f9d97940f21019fdd4da822162678267/Mod_Date.bas -------------------------------------------------------------------------------- /Mod_Files.bas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/carvetighter/VBA-Code-Library/041882b8f9d97940f21019fdd4da822162678267/Mod_Files.bas -------------------------------------------------------------------------------- /Mod_Main.bas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/carvetighter/VBA-Code-Library/041882b8f9d97940f21019fdd4da822162678267/Mod_Main.bas -------------------------------------------------------------------------------- /Mod_Outlook.bas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/carvetighter/VBA-Code-Library/041882b8f9d97940f21019fdd4da822162678267/Mod_Outlook.bas -------------------------------------------------------------------------------- /Mod_Pivot.bas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/carvetighter/VBA-Code-Library/041882b8f9d97940f21019fdd4da822162678267/Mod_Pivot.bas -------------------------------------------------------------------------------- /Mod_PowerPoint.bas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/carvetighter/VBA-Code-Library/041882b8f9d97940f21019fdd4da822162678267/Mod_PowerPoint.bas -------------------------------------------------------------------------------- /Mod_Queries.bas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/carvetighter/VBA-Code-Library/041882b8f9d97940f21019fdd4da822162678267/Mod_Queries.bas -------------------------------------------------------------------------------- /Mod_Row.bas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/carvetighter/VBA-Code-Library/041882b8f9d97940f21019fdd4da822162678267/Mod_Row.bas -------------------------------------------------------------------------------- /Mod_Search.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "Mod_Search" 2 | Option Explicit 3 | Option Base 1 4 | Function Search_Log(wksSheet As Worksheet, longColumn As Long, variantValue As Variant, booleanString As Boolean) As Variant 5 | ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 6 | ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 7 | ' This function searches a worksheets column by a simple logrithmic algorithm 8 | ' for a specific value. 9 | ' 10 | ' ** Note: must have a header row 11 | ' 12 | ' Requirements: 13 | ' Row_GetLast() 14 | ' AutoFilter_Clear() 15 | ' 16 | ' wksSheet: 17 | ' Type: worksheet 18 | ' Desc: worksheet data to search is in 19 | ' 20 | ' longColumn 21 | ' Type: long 22 | ' Desc: column to be searched 23 | ' 24 | ' variantValue 25 | ' Type: variant 26 | ' Desc: value searching for 27 | ' 28 | ' booleanString 29 | ' Type: boolean 30 | ' Desc: flag if is string 31 | ' 32 | ' Return: 33 | ' variable 34 | ' Type: variant 35 | ' Desc: return false if not detected, worksheet row if found 36 | ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 37 | ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 38 | ' declare 39 | Dim longLowerRow As Long, longUpperRow As Long, longTestRow As Long, longMaxLoop As Long, longCounter As Long 40 | Dim int_dollar_posit As Integer 41 | Dim stringColumn As String 42 | Dim variantReturnValue As Variant 43 | 44 | ' loop variables 45 | Dim a As Long 46 | 47 | ' initialize 48 | longLowerRow = 2 49 | longUpperRow = 2 50 | longTestRow = 2 51 | longMaxLoop = 1 52 | longCounter = 0 53 | stringColumn = "tsma" 54 | variantReturnValue = False 55 | 56 | ' loop variable 57 | a = 1 58 | 59 | ' start 60 | ' get the column string 61 | stringColumn = Left(Cells(1, longColumn).Address(RowAbsolute:=True, ColumnAbsolute:=False), 1) 62 | int_dollar_posit = InStr(1, stringColumn, "$") 63 | stringColumn = Left(stringColumn, int_dollar_posit - 1) 64 | 65 | ' short worksheet by column 66 | Call AutoFilter_Clear 67 | wksSheet.Autofilter.Sort.SortFields.Add Key:=Range(stringColumn & ":" & stringColumn), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal 68 | With wksSheet.Autofilter.Sort 69 | .Header = xlYes 70 | .MatchCase = False 71 | .Orientation = xlTopToBottom 72 | .SortMethod = xlPinYin 73 | .Apply 74 | End With 75 | 76 | ' get last row and max number of loops 77 | longUpperRow = Row_GetLast(wksSheet, longColumn) 78 | longMaxLoop = Int((Log(CDbl(longUpperRow - longLowerRow + 1)) / Log(2#)) + 1) 79 | 80 | ' start loop 81 | For a = 1 To longMaxLoop 82 | ' get the row to test 83 | longTestRow = Int((longUpperRow - longLowerRow) / 2) + longLowerRow 84 | 85 | ' special case; only two rows to test 86 | If longUpperRow - longLowerRow = 1 Then 87 | If booleanString = True Then 88 | If StrComp(Trim(Cells(longTestRow, longColumn).Value), variantValue, vbTextCompare) = 0 Then 89 | variantReturnValue = longTestRow 90 | ElseIf StrComp(Trim(Cells(longTestRow + 1, longColumn).Value), variantValue, vbTextCompare) = 0 Then 91 | variantReturnValue = longTestRow 92 | Else ' do nothing 93 | End If 94 | Exit For 95 | Else 96 | If Cells(longTestRow, longColumn).Value = variantValue Then 97 | variantReturnValue = longTestRow 98 | ElseIf Cells(longTestRow + 1, longColumn).Value = variantValue Then 99 | longLowerRow = longTestRow 100 | Else ' do nothing 101 | End If 102 | Exit For 103 | End If 104 | Else ' conduct test 105 | ' test value in cell 106 | If booleanString = True Then 107 | If StrComp(Trim(Cells(longTestRow, longColumn).Value), variantValue, vbTextCompare) = 0 Then 108 | variantReturnValue = longTestRow 109 | Exit For 110 | ElseIf StrComp(Trim(Cells(longTestRow, longColumn).Value), variantValue, vbTextCompare) = -1 Then 111 | longUpperRow = longTestRow 112 | ElseIf StrComp(Trim(Cells(longTestRow, longColumn).Value), variantValue, vbTextCompare) = 1 Then 113 | longLowerRow = longTestRow 114 | Else ' do nothing 115 | End If 116 | Else 117 | If Cells(longTestRow, longColumn).Value = variantValue Then 118 | variantReturnValue = longTestRow 119 | Exit For 120 | ElseIf Cells(longTestRow, longColumn).Value < variantValue Then 121 | longLowerRow = longTestRow 122 | ElseIf Cells(longTestRow, longColumn).Value > variantValue Then 123 | longUpperRow = longTestRow 124 | Else ' do nothing 125 | End If 126 | End If 127 | End If 128 | Next a 129 | 130 | ' return value 131 | Search_Log = variantReturnValue 132 | End Function 133 | 134 | -------------------------------------------------------------------------------- /Mod_String.bas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/carvetighter/VBA-Code-Library/041882b8f9d97940f21019fdd4da822162678267/Mod_String.bas -------------------------------------------------------------------------------- /Mod_Workbook.bas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/carvetighter/VBA-Code-Library/041882b8f9d97940f21019fdd4da822162678267/Mod_Workbook.bas -------------------------------------------------------------------------------- /Outlook - Email from Excel.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/carvetighter/VBA-Code-Library/041882b8f9d97940f21019fdd4da822162678267/Outlook - Email from Excel.docx -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VBA-Code-Library 2 | 3 | The VBA library is a set of methods that I have used over the years to help me work accurately and efficiently. I inldued the modules so others can use and modify for their own use. 4 | 5 | The Excel file has all the modules and all the references included to be able to use once downloaded. 6 | 7 | Mod_Autofilter.bas methods: 8 | - AutoFilter_Clear -> clears the autofilter 9 | - Autofilter_OnOff -> turns the autogilter on or off 10 | - Autofilter_SimpleSort -> simple sort 11 | 12 | Mod_Cells.bas methods: 13 | - Cells_Format -> formats all the cells in a worksheet 14 | - Cells_IsString -> determines if a cell values is a string 15 | - Cells_ReturnNumberOrLetters -> used in Row_GetLast and Column_GetLast for the return value but not limited to only those methods 16 | 17 | Mod_Charts.bas methods: 18 | - Chart_New -> creates a graph with a single series based on a specific format 19 | - Chart_Line -> creates a line graph based on a simple format 20 | - Chart_DeleteAll -> detltes all the graphs in a worksheet 21 | 22 | Mod_Column.bas methods: 23 | - Column_CopyPaste -> copy and paste a column from one worksheet to another 24 | - Column_Find -> find a column based on a string passed 25 | - Column_FindByDate -> find a column based on a date 26 | - Column_FindByTimePeriod -> find a column based on the time period from the last column with a date 27 | - Column_GetCriteria -> get all the unique values in a column 28 | - Column_GetCriteriaByColumn -> get all the unique values of the columsn from the first column to the last column with data in it 29 | - Column_GetLast -> get the last column in a row with data in it 30 | - Column_InsertWithHeader -> insert a column with a header to the left of a column 31 | - Column_TakeOutBlankCells -> delete all the rows with no values in a column 32 | 33 | Mod_Date.bas methods: 34 | - Date_GetHoursMinutesSeconds -> finds the hours, minutes and seconds 35 | 36 | Mod_Files.bas methods: 37 | - Files_ArchiveSource -> archives all the files in the source folder to an archive folder 38 | - Files_Count -> count the number of files in a folder 39 | - Files_FindXlsx -> find *.xlsx files for the OSx version of Microsoft Office 40 | - Files_GetNames -> get the names of all files in a folder 41 | - Files_GetPath -> get the file path that user selects from a dialog window 42 | 43 | Mod_Main.bas methods: 44 | - Main -> template for a main method 45 | 46 | Mod_Outlook.bas methods: 47 | - Application_ItemSend -> BCC every email sent to a specified email 48 | - Outlook_SendEmail -> example of sending an email from Excel through Outlook 49 | 50 | Mod_Pivot.bas methods: 51 | - Pivot_Get -> finds and returns specifid pivot table 52 | - Pivto_SetFieldValues -> set specific values in a pivot field 53 | 54 | Mod_PowerPoint methods: 55 | - PowerPoint_AppendsixSlide -> an example on how to create a PowerPoint slide from a PowerPoint presentation and add data / objects from Excel 56 | - PowerPoint_CutPasteChartsFromExcel -> an example of how to cut and paste charts from Excel to PowerPoint 57 | - PowerPoint_IDShape -> identifies the type of PowerPoint shape 58 | - PowerPoint_ModifyTitle -> an example of how to modify a slide title in PowerPoint 59 | - PowerPoint_TestGroupItems -> determines if a shape is grouped or not 60 | 61 | Mod_Queries.bas methods: 62 | - Query_Refresh -> a simple method that refreshes the SQL queries of all the workshees in the workbooks collection 63 | - Query_Website -> copies all the information from a website to an Excel worksheet 64 | 65 | Mod_Row.bas methods: 66 | - Row_Copy -> copies row from one worksheet to another 67 | - Row_CountVisible -> counts the visible cells in a row 68 | - Row_Find -> finds a row based on a specific criteria 69 | - Row_FindAndDelete -> finds a row and deletes it 70 | - Row_FindByFirstWord -> finds a row by the first work in the cell 71 | - Row_FindTransition -> finds the row of a column where it transitoins from data in a series of cells to no data in a cell or no data in a series of cells to data in a cell 72 | - Row_GetCriteria -> gets all the unique values of a row 73 | - Row_GetCriteriaByRow -> gets all the unique values of the rows from the first row to the last row ith data in it 74 | - Row_GetLast -> finds the last row with data in a specified column 75 | - Row_Insert -> insert a specifiec number of rows above a specific row 76 | - Row_Unhide -> unhides all rows between two specified rows 77 | 78 | Mod_Search.bas methods: 79 | - Search_Log -> conducts a simple log search (not optimized) of column 80 | 81 | Mod_String.bas methods: 82 | - String_FindAllPositOfChar -> finds all the positions of a single charcter in a string 83 | 84 | Mod_Workbook.bas methods: 85 | - Workbook_Clear -> formats every worksheet in a workbook 86 | - Workbook_Find -> finds a specific workbook in the Excel application by name 87 | - Workbook_FindOrCreate -> finds a specific workbook and if not creates a new one 88 | 89 | Mod_Worksheet.bas methods: 90 | - Worksheet_Clear -> formats a worksheet to a specified format 91 | - Worksheet_FindOrCreate -> finds a worksheet by the name or if not creates a new one 92 | -------------------------------------------------------------------------------- /VBA_Code_Library.xlsm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/carvetighter/VBA-Code-Library/041882b8f9d97940f21019fdd4da822162678267/VBA_Code_Library.xlsm --------------------------------------------------------------------------------