This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
Private Sub Worksheet_SelectionChange(ByVal Target As Range) | |
'Set the context appropriately using With...End With | |
With Sheets("calendar") | |
'Clear all previously-applied highlighting for easy readability | |
.Cells.Interior.ColorIndex = xlColorIndexNone | |
'Switch on the address of the selected cell |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'This subroutine creates adds the filtered data from Sheet1 | |
'to a previously-existing destination Worksheet (called "Destination" here) | |
Public Sub AddToDestinationWorksheet(StartDate As String, EndDate As String) | |
'... | |
'Lots of code taken out here for brevity, the first place we're going to replace | |
'the old clear filters logic starts on line 38 of the original | |
'... | |
'Replaced the commented-out code with our new Subroutine, you should actually |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' | |
'INPUT : Sheet, the Worksheet to turn off (clear) filters on | |
'DESCRIPTION : This sub clears (turns off) all filters on a Worksheet | |
'SPECIAL CASE: none | |
Public Sub ClearAllFilters(Sheet As Worksheet) | |
Sheet.AutoFilterMode = False | |
If Sheet.FilterMode = True Then | |
Sheet.ShowAllData | |
End If | |
End Sub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'This subroutine creates adds the filtered data from Sheet1 | |
'to a previously-existing destination Worksheet (called "Destination" here) | |
Public Sub AddToDestinationWorksheet(StartDate As String, EndDate As String) | |
Dim wksData As Worksheet, wksTarget As Worksheet | |
Dim lngLastRow As Long, lngLastCol As Long, lngDateCol As Long, _ | |
lngDestinationLastRow As Long, lngDestinationFirstCol As Long | |
Dim rngFull As Range, rngResult As Range, rngTarget As Range | |
Dim varFiltered As Variant | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
'This subroutine prompts the user to select dates | |
' | |
'Code already written and described here: | |
'http://danwagner.co/how-to-copy-data-to-a-new-workbook-based-on-dates/ | |
Public Sub PromptUserForInputDates() | |
Dim strStart As String, strEnd As String, strPromptMessage As String | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
'This subroutine prompts the user to select dates | |
' | |
'Code already written and described here: | |
'http://danwagner.co/how-to-copy-data-to-a-new-workbook-based-on-dates/ | |
Public Sub PromptUserForInputDates() | |
Dim strStart As String, strEnd As String, strPromptMessage As String | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
Public Sub WriteFakeLastNames() | |
Dim wksNames As Worksheet | |
Dim lngLastRow As Long, lngIdx As Long | |
Dim strOldName As String, strNewName As String | |
'Set references up-front | |
Set wksNames = ThisWorkbook.Worksheets("names") | |
lngLastRow = 1001 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Sub WriteUniquesToNewSheet() | |
Dim wksUniques As Worksheet | |
Dim rngUniques As Range, rngTarget As Range | |
Dim strPrompt As String | |
Dim varUniques As Variant | |
Dim lngIdx As Long | |
Dim colUniques As Collection | |
Set colUniques = New Collection | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Function CollectUniques(rng As Range) As Collection | |
Dim varArray As Variant, var As Variant | |
Dim col As Collection | |
'Guard clause - if Range is nothing, return a Nothing collection | |
'Guard clause - if Range is empty, return a Nothing collection | |
If rng Is Nothing Or WorksheetFunction.CountA(rng) = 0 Then | |
Set CollectUniques = col | |
Exit Function |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
Public Sub CombineDataFromAllSheets() | |
Dim wksSrc As Worksheet, wksDst As Worksheet | |
Dim rngSrc As Range, rngDst As Range | |
Dim lngLastCol As Long, lngSrcLastRow As Long, lngDstLastRow As Long | |
'Notes: "Src" is short for "Source", "Dst" is short for "Destination" | |
'Set references up-front |