Skip to content

Instantly share code, notes, and snippets.

View Se7enSquared's full-sized avatar
🐍
import this

HGray Se7enSquared

🐍
import this
View GitHub Profile
Sub RefreshPivotCache()
Dim ws As Worksheet
Dim PT As PivotTable
For Each ws In ActiveWorkbook.Worksheets '<~~ Loop all worksheets in workbook
For Each PT In ws.PivotTables '<~~ Loop all pivot tables in worksheet
PT.PivotCache.Refresh
Next PT
Next ws
End Sub
Function StringCountOccurrences(strText As String, strFind As String, _
Optional lngCompare As VbCompareMethod) As Long
' Counts occurrences of a particular character or characters.
' If lngCompare argument is omitted, procedure performs binary comparison.
'Testcases:
'?StringCountOccurrences("","") = 0
'?StringCountOccurrences("","a") = 0
'?StringCountOccurrences("aaa","a") = 3
'?StringCountOccurrences("aaa","b") = 0
'?StringCountOccurrences("aaa","aa") = 1
'---------------------------------------------------------------------------------------------------
'Sub: InsertVlookup
'Purpose: Runs a vlookup with given parameters and formats as values and sets column width
' removes both errors & 0's
'Example call: InsertVlookup "O", "B6", "NotesHistory!$B:$J", "9", 30
'---------------------------------------------------------------------------------------------------
Public Sub InsertVlookup(destination_column_letter As String, lookup_cell As String, lookup_range As String, return_index As String, colum_width As Long)
Dim column_range As Range
Set column_range = notes_sheet.Range(destination_column_letter & FIRST_DATA_ROW & ":" & destination_column_letter & last_used_row)
With column_range
using System.IO;
string connection_string = File.ReadAllText(@"C:\Data\ConStringNoCred.txt");
Function GetStringFromFile(filepath As String) As String
On Error GoTo 0
Dim iFile As Integer: iFile = FreeFile
Open filepath For Input As #iFile
GetStringFromFile = Input(LOF(iFile), iFile)
Close #iFile
End Function
private void txtSearch_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
searchDb();
}
}
'--------------------------------------------------------------------------------------------------
' Sub: SaveToSharePoint
' Params: main_folder_path: the path to the main folder on sharepoint. If the
' report will save into individual subfolders, those are
' specified in the sub_folder variable
' NOTE: "https://hp.sharepoint.com/teams/WS OEM PRGM/" is
' already defined in the subroutine. This is every thing
' after that (for example: "Shared Documents/CLS Reports" NO / before or after
' workbook_to_save: the actual workbook object being saved
'----------------------------------------------------------------
' Sub: DeleteBlankSheets
' Purpose: Deletes all blank sheets in workbk
' Params: workbk: Workbook: The workbook to delete the sheets in
' Last Update: 2/1/2021
' Author: Gray
'-----------------------------------------------------------------
Public Sub DeleteBlankSheets(ByVal workbk As Workbook)
Dim sh As Worksheet
' ----------------------------------------------------------------
' Function: ReturnColumnLetter
' Purpose: Given a column number, returns the letter as a string
' Params: col_num: Integer: the column number to convert
' Author: Gray
' Date: 1/19/2021
' ----------------------------------------------------------------
Function ReturnColumnLetter(ByVal num As Integer) As String
ReturnName = Split(Cells(, num).Address, "$")(1)
End Function