Skip to content

Instantly share code, notes, and snippets.

@ateneva
ateneva / CellInR_EncloseInQuotes.bas
Last active April 15, 2018 10:21
Enclose string in single quotes
Sub EncloseinQuotes()
Dim Cell As Range
Dim IP As String
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'written by Angelina Teneva, March 2017
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
With ActiveSheet
For Each Cell In Range("A2:A" & ActiveSheet.UsedRange.Rows.Count)
@ateneva
ateneva / CellInR_InsertSpacesBetweenCharactersCase.bas
Last active April 16, 2017 15:55
Insert spaces between uppercase characters
Sub InsertSpacesBetweenCharactersCase()
Dim mStr As String
Dim i As Integer
Dim Cell As Range
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'written by Angelina Teneva, March 2017
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For Each Cell In ActiveSheet.Range("G3:G43")
@ateneva
ateneva / CellInR_FindFirstUpperChar.bas
Last active April 16, 2017 15:54
Insert a space after the first uppercase character it finds in a string
Sub FindFirstUpperCharacter()
Dim mStr As String
Dim FindUpper As String
Dim FindLower As String
Dim i As Integer
Dim Cell As Range
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'assumes the string has only two Upper characters that need separating by blank space; Angelina Teneva, March 2017
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ateneva
ateneva / CellInR_ColourWordsInString.bas
Last active April 18, 2018 13:41
Finds a word in a string (if it exists) and colours it red
Sub ColourWordsInString()
Dim Cell As Range
Dim i As Integer
Dim prv As String
Dim word As String
Dim positive(1 To 5) As String
Dim negative(1 To 5) As String
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ateneva
ateneva / CellInR_ColourCellsOnAbsValues.bas
Last active April 15, 2018 17:31
Colour cells that have absolute value greater than 1.96
Sub ColourCellsonAbsoluteValues()
Dim Cell As Range
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'written by Angelina Teneva, September 2016
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For Each Cell In Selection
Cell.Activate
If Cell.Value < 0 Then
@ateneva
ateneva / CellInR_ColourCellsInAdjacentColumns.bas
Last active April 18, 2018 08:38
Colour a range of cells if they meet a certain condition
Sub ColourCellsin_DifferentColumn()
Dim Cell As Range
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'written by Angelina Teneva, September 2016
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For Each Cell In Range("F5:F" & ActiveSheet.UsedRange.Rows.Count)
Cell.Activate
Range(ActiveCell.Offset(0, -5), ActiveCell.Offset(0, 4)).Font.Color = RGB(0, 0, 0) 'black (reset any previous formatting)
@ateneva
ateneva / CellInR_FillInEmptyCellWithConstant.bas
Last active April 16, 2017 15:41
Fill empty cells with a constant
Sub FillInEmptyCellWithConstant()
Dim i As Long
Dim Col As Integer
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'written by Angelina Teneva, September 2016
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For Col = 7 To 68
For i = 1 To Cells(Rows.Count, Col).End(xlUp).row
If IsEmpty(Cells(i, Col)) Then Cells(i, Col).Value = "empty"
@ateneva
ateneva / CellInR_FillInEmptyCellWithPrevious.bas
Last active April 16, 2017 15:41
Fill empty cells with values from the previous cells
Sub FillInEmptyCellWithPrevious()
Dim Cell As Range
Dim Region As Range
Set Region = Worksheets("Extract").Range(Cells(3, 1), Cells(ActiveSheet.UsedRange.Rows.Count, 3, 3))
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'written by Angelina Teneva, September 2016
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For Each Cell In Region
@ateneva
ateneva / CellInR_FillEmptyCellWithAdjacent.bas
Last active April 16, 2017 15:39
Fill empty cell with value from another column
Sub FillInEmptyCellWithAdjacent()
Dim Cell As Range
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'written by Angelina Teneva, September 2016
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'copy to column
For Each Cell In ActiveSheet.Range("AB2:AB" & ActiveSheet.UsedRange.Rows.Count)
Cell.Activate