Skip to content

Instantly share code, notes, and snippets.

View Se7enSquared's full-sized avatar
🐍
import this

HGray Se7enSquared

🐍
import this
View GitHub Profile
' ----------------------------------------------------------------
' 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
private void txtSearch_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
searchDb();
}
}
'---------------------------------------------------------------------------------------------------
'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
Private Sub ClearAllFilters()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.ShowAllData
Next ws
End Sub
'EXAMPLE CALL:
' To clipboard:
' Dim string_to_copy As String: string_to_copy = ThisWorkbook.Worksheets("Sheet1").Range("A1").Value
' Clipboard (string_to_copy)
' From clipboard:
' Dim in_clipbaord As String
' in_clipboard = Clipboard()
'------------------------------------------------------------------
' Function: Clipboard
' Purpose: Read from (if no variable passed) or write variable
Public Sub CopyUsedRangeFromExternalWBToTable(source_ws_number As Long, wb As Workbook, dest_sheet As String, dest_range As String)
wb.Worksheets(source_ws_number).UsedRange.Copy
ThisWorkbook.Worksheets(dest_sheet).Range(dest_range).PasteSpecial Paste:=xlPasteValues
End Sub
' ----------------------------------------------------------------
' Function: ChooseExcelFile
' Purpose: Get the location of the chosen excel file from dialog
' Params: String: starting_path: The folder to open the dialog in
' example: Environ$("USERPROFILE") & "\Downloads" or
' example2: C:\Data (no ending \)
' Returns: String: The full path to the chosen excel file as string
' By: HG
' Date: 12/21/2021
' ----------------------------------------------------------------
@Se7enSquared
Se7enSquared / Is value in excel table column.vbs
Last active November 29, 2021 20:02
Returns true if the given search term is found in a listRange
' ----------------------------------------------------------------
' Function: IsValueInList
' Purpose: Pass in a search term and function will tell you if it's in the given table.
' Assumptions: There is a named single-column Excel Table Object in the given worksheet
' Params:
' searchTerm: String: the item to look for in the list
' sheet: String: the sheet name where the lookup table is located
' list: String: the name of the Excel Table object where we want to look for the searchTerm
@Se7enSquared
Se7enSquared / Get Value from Selected Cell.vbs
Last active November 29, 2021 19:59
Stores the value of a cell in a variable when the selection changes
' Stores the value of the selected cell in a variable
Dim prevValue As String
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim prevValue As String
On Error Resume Next
If Intersect(Target, Range("G:K")) Is Nothing Then
prevValue = ""
Else
prevValue = Target.Value
'----------------------------------------------------------------------------------
' Function: ValueInTable
' Purpose: Given a list object and column number, look up the given value
' in a column and return "True" if found
' Params: column_number Long the columns number to find the value in
' (this number is relative to the beginning
' of the data body range of the list object,
' not the total number of columns in the sheet)
' tbl ListObject The listobject to search
' LookupValue String The value to find