Delete Blank Rows in Excel
Delete Blank Rows in Excel
Sub DeleteEmptyRows()
'
'This macro will delete all rows, which are missing data in a
'particular column, underneath and including the selected cell.
'
Dim Counter
Dim i As Integer
Next i
End Sub
Sub Delete_Empty_Columns()
first = Selection.Column
last = Selection.Columns(Selection.Columns.Count).Column
Next i
End Sub
first = Selection.Column
last = Selection.Columns(Selection.Columns.Count).Column
For i = last To first Step -1
Next i
End Sub
Sub Sort_Worksheets()
Dim i As Integer
Dim j As Integer
Dim iAnswer As VbMsgBoxResult
End If
End If
Next j
Next i
End Sub
Sub bubble_sort()
sortingArray = Selection.Value
For i = 1 To (UBound(sortingArray, 1) - 1)
For j = i To UBound(sortingArray, 1)
If Val(sortingArray(j, 1)) < Val(sortingArray(i, 1)) Then
temp = sortingArray(i, 1)
sortingArray(i, 1) = sortingArray(j, 1)
sortingArray(j, 1) = temp
End If
Next j
Next i
Selection.Value = sortingArray
End Sub
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
Rw = 0
For Each C In Rng
Arr(Rw) = C.Formula
Rw = Rw + 1
Next C
Rw = Rw - 1
For Each C In Rng
C.Formula = Arr(Rw)
Rw = Rw - 1
Next C
EndMacro:
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
End Sub
Sub Reverse_Cell_Contents()
Excel Macro to Filter Data to Display the Results that Begin With
Specified Text or Words in Excel - AutoFilter
Sub AutoFilter_Begins_With()
'Put the * mark after the word in which you would like to filter for
this macro
End Sub
Excel Macro to Filter Data to Show Only the Bottom 10 Items in
Excel - AutoFilter
Sub AutoFilter_Bottom_10_Items()
End Sub
Sub AutoFilter_Bottom_10_Percent()
End Sub
Sub AutoFilter_Bottom_X_Number_Items()
'Replace the "#" sign with the bottom number of items you would like to
have displayed
End Sub
Sub AutoFilter_Bottom_X_Percent_Items()
'Replace the "#" sign with the bottom percentage of items you would like
to have displayed
End Sub
Range("A1").AutoFilter
End Sub
Sub AutoFilter_in_Excel()
End Sub
Sub AutoFilter_in_Excel_AND_Operator_One_Field()
End Sub
Sub AutoFilter_in_Excel_Above_Below_Num()
'This autofilter macro displays records with a number between 50000 and
75000 within the first field - in this case in column A
'It is important to retain the ">" and "<" signs within this macro
because that it what makes this work correctly
End Sub
Sub AutoFilter_in_Excel_Multiple_Col_Filter()
Sub AutoFilter_in_Excel_No_Arrow()
'This option is a bit finicky depending on how many of the fields you
want the drop-down arrow to not be displayed over.
'By default, the visibledropdown option being set to false will only
remove the drop-down arrow from the frield(s) being filtered.
End Sub
Sub AutoFilter_in_Excel_OR_Operator_One_Field()
End Sub
Sub AutoFilter_Remove()
'This macro removes any filtering in order to display all of the data
but it does not remove the filter arrows
ActiveSheet.ShowAllData
End Sub
Excel Macro to Filter Data to Show the Top 10 Items from a Data
Set in Excel - AutoFilter
Sub AutoFilter_Top_10_Items()
End Sub
Excel Macro to Filter Data to Show the Top 10 Percent of the Data
Set in Excel - AutoFilter
Sub AutoFilter_Top_10_Percent()
End Sub
Sub AutoFilter_Top_X_Percent_Items()
'Replace the "#" sign with the top percentage of items you would like to
have displayed
End Sub
Sub AutoFilter_Top_X_Number_Items()
'Replace the "#" sign with the top number of items you would like to
have displayed
End Sub
Sub Sort_Ascending_Basic()
'Sorts a worksheet in ascending order and assumes there are no headers
on the data
Range("A1:C56").Sort _
Key1:=Range("A1"), Header:=xlNo
End Sub
Sub Sort_Ascending_With_Header()
'Sorts a worksheet in ascending order and assumes there are headers on
the data
Range("A1:C56").Sort _
Key1:=Range("A1"), Header:=xlYes
End Sub
Sub Sort_Descending_Basic()
'Sorts a worksheet in descending order and assumes there are no headers
on the data
Range("A1:C56").Sort _
Key1:=Range("A1"), Order1:=xlDescending, Header:=xlNo
End Sub
Sub Sort_Descending_Basic_With_Header()
'Sorts a worksheet in descending order and assumes there are headers on
the data
Range("A1:C56").Sort _
Key1:=Range("A1"), Order1:=xlDescending, Header:=xlYes
End Sub
Sub Basic_Web_Query()
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://finance.yahoo.com/q?s=goog", Destination:=Range("$A$1"))
.Name = "q?s=goog_2"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "1,2"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub
Sub Send_Email_Current_Workbook()
.Send
End With
On Error GoTo 0
Sub SendOutlookMessages()
Set OL = CreateObject("Outlook.Application")
Set MailSendItem = OL.CreateItem(olMailItem)
ToRangeCounter = 0
With MailSendItem
.Subject = ActiveSheet.Range("subjectcell").Text
.Body = MsgTxt
Set OL = Nothing
End Sub
Sub GetChartValues()
'This macro will retrieve the source data from a chart in excel
'This works for charts where the source data has been lost or
'damaged.
'Simply select the chart and run the macro - make sure to create a
'separate worksheet titled "ChartData" first though.
'
Dim NumberOfRows As Integer
Dim X As Object
Counter = 2
NumberOfRows = UBound(ActiveChart.SeriesCollection(1).Values)
Worksheets("ChartData").Cells(1, 1) = "X Values"
With Worksheets("ChartData")
.Range(.Cells(2, 1), _
.Cells(NumberOfRows + 1, 1)) = _
Application.Transpose(ActiveChart.SeriesCollection(1).XValues)
End With
For Each X In ActiveChart.SeriesCollection
Worksheets("ChartData").Cells(1, Counter) = X.Name
With Worksheets("ChartData")
.Range(.Cells(2, Counter), _
.Cells(NumberOfRows + 1, Counter)) = _
Application.Transpose(X.Values)
End With
Counter = Counter + 1
Next
End Sub
Excel Macro to Delete All Chart Sheets in Excel - Only Chart Sheets
are Deleted - Not Embedded Charts
Sub delete_all_chart_sheets_in_workbook()
'This example deletes every chart sheet in the active workbook.
ActiveWorkbook.Charts.Delete
End Sub
Sub Create_Line_Chart()
'create a line chart in excel with this macro
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range("'Sheet1'!$A$1:$B$67")
ActiveChart.ChartType = xlLine
End Sub
Sub Create_Bar_Chart()
'create a bar chart in excel with this macro
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range("'Sheet1'!$A$1:$B$67")
ActiveChart.ChartType = xlBarClustered
End Sub
Sub Create_Column_Chart()
'create a column chart with this excel macro
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range("'Sheet1'!$A$1:$B$67")
ActiveChart.ChartType = xlColumnClustered
End Sub
Sub Format_Cell_Accounting()
End Sub
Sub Format_Cell_Currency_US_Dollar()
Selection.NumberFormat = "$#,##0.00"
End Sub
Sub Format_Cell_Date_Long()
End Sub
Sub Format_Cell_Date_Short()
Selection.NumberFormat = "m/d/yyyy"
End Sub
Sub Format_Cell_Fraction()
End Sub
Selection.NumberFormat = "General"
End Sub
Sub Format_Cell_Number()
Selection.NumberFormat = "0.00"
End Sub
Sub Format_Cell_Percentage()
Selection.NumberFormat = "0.00%"
End Sub
Sub Format_Cell_Scientific()
Selection.NumberFormat = "0.00E+00"
End Sub
Sub Format_Cell_Text()
Selection.NumberFormat = "@"
End Sub
Sub Format_Cell_Time()
End Sub
Excel Macro to Highlight Every Other Row in a Selection in Excel -
Table Formatting
Sub Highlight_Every_Other_Row()
'This macro highlights every other row within a selection of rows - you
select the table/rows you want formatted
Dim r As Integer
For r = 1 To Selection.Rows.Count
If r Mod 2 = 1 Then
Selection.Rows(r).Interior.ColorIndex = 37
End If
Next
End Sub
Sub Add_Drop_Down_Menu_Cell()
With Range("A1").Validation
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:=xlBetween, _
Formula1:="=$D$1:$D$3"
.IgnoreBlank = True
.InCellDropdown = True
End With
End Sub
With Selection.Validation
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:=xlBetween, _
Formula1:="=$D$1:$D$3"
.IgnoreBlank = True
.InCellDropdown = True
End With
End Sub
Free Excel Macro to Add an Input Message to a Specified Cell in
Excel
Sub Add_Cell_Input_Message_Cell()
With Range("A1").Validation
.Add Type:=xlValidateInputOnly
.InputTitle = "Message Title Goes Here"
.InputMessage = "Message Contents Go Here"
End With
End Sub
With Selection.Validation
.Add Type:=xlValidateInputOnly
.InputTitle = "Message Title Goes Here"
.InputMessage = "Message Contents Go Here"
End With
End Sub
Sub Remove_Data_Validation_Cell()
Range("A1").Validation.Delete
End Sub
Selection.Validation.Delete
End Sub
UDF to Count The Number of Words in a Cell or Range of Cells in
Excel
Next rCell
COUNTWORDS = lCount
End Function
If IsMissing(separator) Then
separator = " "
End If
Next rCell
COUNTWORDSC = lCount
End Function
FVCOMPOUNDINTEREST = PV * (1 + r) ^ N
End Function
If IsMissing(Delimiter) Then
Delimiter = " "
End If
End Function
Application.Volatile
iArr(i) = i
Next i
temp = iArr(r)
iArr(r) = iArr(i)
iArr(i) = temp
Next i
For i = Bottom To Bottom + Amount - 1
Next i
RANDNUMNOREP = Trim(RANDNUMNOREP)
End Function
If IsMissing(Default) Then
SHOWLINK = "Not a Link"
Else
SHOWLINK = Default
End If
Else
End If
End Function
With wSheet
End With
Next wSheet
VLOOKUPWORKBOOK = vFound
End Function
End Function
End Function
UDF to Return the ISO Standards Start of the Year in Excel - First
Monday of the Year
End Function
Option Explicit
'Main Function
Function SPELLDOLLAMNT(ByVal MyNumber)
Dim Dollars, Cents, Temp
Dim DecimalPlace, Count
ReDim Place(9) As String
Place(2) = " Thousand "
Place(3) = " Million "
Place(4) = " Billion "
Place(5) = " Trillion "
' String representation of amount.
MyNumber = Trim(Str(MyNumber))
' Position of decimal place 0 if none.
DecimalPlace = InStr(MyNumber, ".")
' Convert cents and set MyNumber to dollar amount.
If DecimalPlace > 0 Then
Cents = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & _
"00", 2))
MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
End If
Count = 1
Do While MyNumber <> ""
Temp = GetHundreds(Right(MyNumber, 3))
If Temp <> "" Then Dollars = Temp & Place(Count) & Dollars
If Len(MyNumber) > 3 Then
MyNumber = Left(MyNumber, Len(MyNumber) - 3)
Else
MyNumber = ""
End If
Count = Count + 1
Loop
Select Case Dollars
Case ""
Dollars = "No Dollars"
Case "One"
Dollars = "One Dollar"
Case Else
Dollars = Dollars & " Dollars"
End Select
Select Case Cents
Case ""
Cents = " and No Cents"
Case "One"
Cents = " and One Cent"
Case Else
Cents = " and " & Cents & " Cents"
End Select
SPELLDOLLAMNT = Dollars & Cents
End Function
Function SHEETNAME()
SHEETNAME = Range("A1").Parent.Name
End Function
NAMEWORKBOOKEXT = ThisWorkbook.Name
End Function
NAMEWBKFILEPATH = ThisWorkbook.FullName
End Function
End Function
Case 1
strColor = "Black"
iIndexNum = 1
Case 53
strColor = "Brown"
iIndexNum = 53
Case 52
iIndexNum = 52
Case 51
iIndexNum = 51
Case 49
iIndexNum = 49
Case 11
iIndexNum = 11
Case 55
strColor = "Indigo"
iIndexNum = 55
Case 56
strColor = "Gray-80%"
iIndexNum = 56
Case 9
iIndexNum = 9
Case 46
strColor = "Orange"
iIndexNum = 46
Case 12
iIndexNum = 12
Case 10
strColor = "Green"
iIndexNum = 10
Case 14
strColor = "Teal"
iIndexNum = 14
Case 5
strColor = "Blue"
iIndexNum = 5
Case 47
strColor = "Blue-Gray"
iIndexNum = 47
Case 16
strColor = "Gray-50%"
iIndexNum = 16
Case 3
strColor = "Red"
iIndexNum = 3
Case 45
iIndexNum = 45
Case 43
strColor = "Lime"
iIndexNum = 43
Case 50
iIndexNum = 50
Case 42
strColor = "Aqua"
iIndexNum = 42
Case 41
iIndexNum = 41
Case 13
strColor = "Violet"
iIndexNum = 13
Case 48
strColor = "Gray-40%"
iIndexNum = 48
Case 7
strColor = "Pink"
iIndexNum = 7
Case 44
strColor = "Gold"
iIndexNum = 44
Case 6
strColor = "Yellow"
iIndexNum = 6
Case 4
iIndexNum = 4
Case 8
strColor = "Turqoise"
iIndexNum = 8
Case 33
iIndexNum = 33
Case 54
strColor = "Plum"
iIndexNum = 54
Case 15
strColor = "Gray-25%"
iIndexNum = 15
Case 38
strColor = "Rose"
iIndexNum = 38
Case 40
strColor = "Tan"
iIndexNum = 40
Case 36
iIndexNum = 36
Case 35
iIndexNum = 35
Case 34
iIndexNum = 34
Case 37
iIndexNum = 37
Case 39
strColor = "Lavendar"
iIndexNum = 39
Case 2
strColor = "White"
iIndexNum = 2
Case Else
CELLCOLOR = strColor
Else
CELLCOLOR = iIndexNum
End If
End Function
cmnt = WorksheetFunction.Clean(rCommentCell.Comment.Text)
GETCOMMTEXTWITHAUTH = cmnt
On Error GoTo 0
End Function
cmnt = WorksheetFunction.Clean(rCommentCell.Comment.Text)
On Error GoTo 0
End Function
Sub Open_PowerPoint_Presentation()
objPPT.Presentations.Open "C:\test.ppt"
End Sub
Sub Proper_Case()
'
'This will make the first letter of the text within any selection of
'cells uppercase.
'
For Each x In Selection
x.Value = Application.Proper(x.Value)
Next
End Sub
Sub Protect_All()
For i = 1 To Sheets.Count
Sheets(i).Protect
Next i
End Sub