
Excel Functions and VBA Cheat Sheet by Axcel Security:
https://drive.google.com/file/d/0B5wopjzDUlg-UGthSGNoWVZZOFE/view?usp=sharing
Excel Funtions
Combine two or more text strings into one string
| |
Extract part of a text string (1)
| |
Extract part of a text string (2)
| |
Calculate the length of a string
| |
Calculate the length of a string after removing specific characters
| |
Determine the frequency of a specific character within a string
| |
Eliminate leading, trailing, and excess spaces within a text string
| |
Replace a specific text string with another string
| |
Replace a specific instance of a text string with another string
| |
Replace characters within a text string starting at a specified position
| |
Determine the number of words in a text string
| |
Convert all characters in a string to lowercase
| |
Convert all characters in a string to uppercase
| |
Capitalize the first letter of each word in a string
| |
Remove non-printable characters from a text string
| |
Compare two text strings taking case sensitivity into account
| |
Compare two text strings ignoring case sensitivity
| |
Count occurrences of specific text within a range of cells
| |
Count the number of empty or non-empty cells within a range
| |
Calculate the sum of the products of corresponding values in two ranges
| |
Nested If Statement
| |
3D-reference - Referencing the same cell or range across multiple worksheets
| |
Offset - Referencing a cell relative to a specific cell
| |
Left Lookup - Search for a value in a column and return a corresponding value from another column
| |
Two-way Lookup - Search for a value based on both row and column headers
| |
Find the maximum value within a range
| |
Replace negative numbers with zero
| |
Generate a random number between 0 and 1
| |
Generate a random whole number within specified lower and upper limits
| |
Generate random decimal numbers between two limits
| |
Determine the position of a number within a list
| |
Round a number down to the nearest integer
| |
Remove decimal places from a number
| |
| |
Round a number to the nearest specified multiple
| |
Excel VBA
Display the number of worksheets in a workbook
| |
Create a new workbook
| |
Write a value to a range of cells
| |
Write a value to a named range
| |
Write a value to a specific cell
| |
Dim example As Range Set example = Range(“A1:C4”) example.Value = 8
| |
Dim example As Range Set example = Range(“A1:C4”) example.Select
| |
Dim example As Range Set example = Range(“A1:C4”) example.Rows(3).Select
| |
Dim example As Range Set example = Range(“A1:C4”) example.Columns(2).Select
| |
Range(“C3:C4”).Value = Range(“A1:A2”).Value
| |
Range(“A1”).Value = ""
| |
Dim example As Range Set example = Range(“A1:C4”) MsgBox example.Count ’ return 12 MsgBox example.Rows.Count ’ return 4
| |
Dim x As Integer x = 6 Range(“A1”).Value = x
| |
Dim book As String book = “bible” Range(“A1”).Value = book
| |
Dim x As Integer x = 5.5 MsgBox “value is " & x
| |
Dim continue As Boolean continue = True If continue = True Then MsgBox “TRUE!”
| |
Dim score As Integer, result As String score = Range(“A1”).Value If score >= 60 Then result = “pass” Else result = “fail” End If Range(“B1”).Value = result
| |
Dim i As Integer For i = 1 To 6 Cells(i, 1).Value = 100 Next i
| |
Dim i As Integer i = 1 Do While i < 6 Cells(i, 1).Value = 20 i = i + 1 Loop
| |
Dim text As String text = “example text” MsgBox Left(text, 4) ‘return exam MsgBox Right(“example text”, 2) ‘return xt MsgBox Mid(“example text”, 9, 2) ‘return te MsgBox Len(“example text”) ‘return 12 MsgBox Instr(“example text”, “am”) ‘return 3
| |
Dim Films(1 To 5) As String Films(1) = “Lord of the Rings” Films(2) = “Speed” Films(3) = “Star Wars” Films(4) = “The Godfather” Films(5) = “Pulp Fiction” MsgBox Films(4) ‘return The Godfather
| |
Function Area(x As Double, y As Double) As Double Area = x * y End Function
Dim z As Double z = Area(3, 5) + 2 MsgBox z
| |
Sub Area(x As Double, y As Double) MsgBox x * y End Sub
Area 3, 5
| |
Sub compute()
Dim i As Integer Dim TEMP_ID As String Dim COL_ID_NEW As Integer Dim COL_VL_NEW As Integer Dim COL_VL_NEW_DEFAULT As Integer Dim ROW_ID_NEW As Integer
TEMP_ID = “dummy” ‘Determine the last row containing data LAST_ROW = Cells(Rows.Count, 1).End(xlUp).Row
‘Configuration ‘Specify the column number for the new ID COL_ID_NEW = 4 ‘Specify the initial row number for the new ID ROW_ID_NEW = 1 ‘Specify the column number for the new value COL_VL_NEW = 5 ‘Specify the default column number for the new value COL_VL_NEW_DEFAULT = 5 ‘Specify the last column to be removed LAST_COL_DEL = 3
‘Set column titles Range(“D1”).Value = “ID” Range(“E1”).Value = “Value 1” Range(“F1”).Value = “Value 2” Range(“G1”).Value = “Value 3”
‘Process each row until the last row with data For i = 2 To LAST_ROW ‘Get the current ID and Value CURR_ID = Cells(i, 1).Value CURR_VALUE = Cells(i, 2).Value
‘If the current ID matches the previous ID If CURR_ID = TEMP_ID Then ‘Move to the next column for the new value COL_VL_NEW = COL_VL_NEW + 1 ‘Copy the value to the corresponding cell Cells(ROW_ID_NEW, COL_VL_NEW).Value = CURR_VALUE
‘If a new ID is encountered Else ‘Update the previous ID with the current ID TEMP_ID = CURR_ID ‘Reset the column number for the new value COL_VL_NEW = COL_VL_NEW_DEFAULT ‘Move to the next row for the new ID ROW_ID_NEW = ROW_ID_NEW + 1 ‘Populate the cells with the current ID and Value Cells(ROW_ID_NEW, COL_ID_NEW).Value = CURR_ID Cells(ROW_ID_NEW, COL_VL_NEW).Value = CURR_VALUE End If Next i
‘Remove unnecessary columns For i = 1 To LAST_COL_DEL Columns(1).EntireColumn.Delete Next i
End Sub
| |