Commands | Description | |
ActiveCell.CurrentRegion.Select | Select a range or block of data (Cells). Keep columns to the left and right clear of data so that they are not apart of the block. | |
Selection.End(xlDown).Select ActiveCell.Offset(1, 0).Range("A1").Select |
End down and offset one cell down | |
Application.ScreenUpdating = False | This is used so that you do not see the macro run.
It makes the macro go faster. Note if you use this the cursor will not follow you to the new cell. |
|
Application.CutCopyMode = False | This is like pressing “Esc” to get rid of the rubber band box. Use this after you have pasted your data. | |
ActiveWorkbook.Save | This will save the workbook | |
ActiveCell.EntireColumn.AutoFit | Adjust current column width | |
Go to randon numbered cell in a list between 1 and 10 | Cells(int(RND*10,1).Select | |
lastrow = Activecell.row |
Makes last choosen cell the active cell. Can be used like Selection.End(xldown).select | |
ActiveCell.EntireColumn.Copy | copy active column | |
Sheets("Sheet3").Select | Go to sheet 3 | |
[a1].Select | Go to a Cell location - If using screen updating the cursor will not follow to active cell | |
Range("A1:D20").Select | Select a Range of cells | |
|
||
Selection.Copy | Copy Active Selection | |
ActiveSheet.Paste | Paste data to ActiveCell | |
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False |
This will change a formula into a value | |
ActiveSheet.PivotTables("PivotTable8") .PivotCache.Refresh |
This will refresh PivotTable8 | |
Excel help: Login = Daniel1 - - PW= Burgersandbeer |
||
vbCrLf |
This will add a Carrage Return in VBA used to concatenate a new line of data (MsgBox = First Line & vbCrLf & Second Line) |
|
Turn on and off the caluculation function | Application.Calculation = xlManual |
|
Copy and paste in one command | Range("A1:A5").copy Destination:=Range("B1") | |
Copy by cell location - Cells(1,5) = Location "E1" or Row 1 column 5 and will copy data to Row 3 column 1 or "A3" |
Cells(1,5).Copy Destination:=Cells(3, 1) | |
FinalRow = Cells(Rows.Count, col).End(xlUp).Row '-This is the same as =CountA(A:A) for the active column. "Col" must be definded. TotalRow = FinalRow + 1 ' - This moves the activecell down one cell |
||
How to add a Key Stroke to activate a macro. | Click Developer tab / click on Macros / click Options |
Name | Type | Details | Symbol |
Byte | Numerical | Whole number between 0 and 255. | |
Integer | Numerical | Whole number between -32'768 and 32'767. | % |
Long | Numerical | Whole number between - 2'147'483'648 and 2'147'483'647. | & |
Currency | Numerical | Fixed decimal number between -922'337'203'685'477.5808 and 922'337'203'685'477.5807. | @ |
Single | Numerical | Floating decimal number between -3.402823E38 and 3.402823E38. | ! |
Double | Numerical | Floating decimal number between -1.79769313486232D308 and 1.79769313486232D308. | # |
String | Text | Text. | $ |
Date | Date | Date and time. | |
Boolean | Boolean | True or False. | |
Object | Object | Microsoft Object. | |
Variant | Any type | Any kind of data (default type if the variable is not declared). |
Sub procedure1() Dim var1 As Integer ' => Use of a variable only within a procedure End Sub Sub procedure2()
|
Dim var1 As Integer Sub procedure1()
Sub procedure2() ' => var1 can also be used here End Sub |
Global var1 As Integer To maintain the value of a variable after the execution of the procedure in which it appears, replace Dim with Static : Sub procedure1() Static var1 As Integer End Sub |
Static Sub procedure1() Dim var1 As Integer End Sub |
= | is equal to |
<> | is different than |
< | is less than |
<= | is less than or eual to |
> | is greater than |
>= | is greater than or equal to |
AND | [condition1] AND [condition2] The two conditions must be true |
OR | [condition1] OR [condition2] At least 1 of the 2 conditions must be true |
NOT | NOT [condition1] The condition should be false |
Sub variables() If IsNumeric(Range("F5")) Then 'IF NUMERICAL Dim last_name As String, first_name As String, age As Integer, row_number As Integer row_number= Range("F5") + 1 If row_number >= 2 And row_number <= 17 Then 'If correct number first_name = Cells(row_number, 2) age = Cells(row_number, 3) MsgBox last_name & " " & first_name & ", " & age & " years old" Range("F5").ClearContents End If Else 'IF NOT NUMERICAL Range("F5").ClearContents End If End Sub |
#1Sub filefolder()Dim name As String name = InputBox("Create new file in C:\Dano") If Len(Dir("c:\Dano\" & name, vbDirectory)) = 0 Then MkDir "c:\Dano\" & name Exit Sub End If MsgBox "Sorry that name already exists please try again" End Sub |
#2Sub copytemplate()' Dim frompath As String Dim topath As String Dim name As String name = InputBox("Name to put template in?") frompath = "C:\Dano\Templa.xlsm" topath = "C:\Dano\" & name & "\" & name & ".xlsm" FileCopy frompath, topath End Sub |
Select | VBA Coding |
---|---|
Entire Table | ActiveSheet.ListObjects("Table1").Range.Select |
Table Header Row | ActiveSheet.ListObjects("Table1").HeaderRowRange.Select |
Table Data | ActiveSheet.ListObjects("Table1").DataBodyRange.Select |
Third Column | ActiveSheet.ListObjects("Table1").ListColumns(3).Range.Select |
Third Column (Data Only) | ActiveSheet.ListObjects("Table1").ListColumns(3).DataBodyRange.Select |
Select Row 4 of Table Data | ActiveSheet.ListObjects("Table1").ListRows(4).Range.Select |
Select 3rd Heading | ActiveSheet.ListObjects("Table1").HeaderRowRange(3).Select |
Select Data point in Row 3, Column 2 | ActiveSheet.ListObjects("Table1").DataBodyRange(3, 2).Select |
Subtotals | ActiveSheet.ListObjects("Table1").TotalsRowRange.Select |
Select | VBA Coding |
---|---|
Insert A New Column 4 | ActiveSheet.ListObjects("Table1").ListColumns.Add Position:=4 |
Insert Column at End of Table | ActiveSheet.ListObjects("Table1").ListColumns.Add |
Insert Row Above Row 5 | ActiveSheet.ListObjects("Table1").ListRows.Add (5) |
Add Row To Bottom of Table | ActiveSheet.ListObjects("Table1").ListRows.Add AlwaysInsert:= True |
Add Totals Row | ActiveSheet.ListObjects("Table1").ShowTotals = True |
Sub orderformActions() If Worksheets("List").Range("P2") = "2" Then Call MoveOrderData If Worksheets("List").Range("P2") = "3" Then Call AddRowToTable5 If Worksheets("List").Range("P2") = "4" Then Call ResetTenRowsOnOrderForm ActiveSheet.Shapes("Drop Down 21").OLEFormat.Object.Value = 1 ActiveWorkbook.Save End Sub |
End Sub
Sub findSR()
[a1].Select
End Sub
Sub findbom()
[a1].Select
Application.EnableCancelKey = xlDisabledin the first line of your macro.. This will fix the problem and you will be able to execute the macro successfully without getting the error message “Code execution has been interrupted”.
Sub copyCD()
'
Dim myname As String
FinalRow = Cells(Rows.Count, 1).End(xlUp).Row
myname = InputBox("What is your name")
[a1].Select
Do
If ActiveCell = myname Then
Range(ActiveCell, ActiveCell.Offset(FinalRow, 0)).Copy Destination:=[F1]
Exit Do
Else
ActiveCell.Offset(0, 1).Select
End If
Loop
End Sub
Sub PrintLetters()
Dim StartRow As Integer, EndRow As Integer
Dim Msg As String
Dim totalRecords As String
Dim firstName As String, lastName As String, address1 As String, address2 As String, city As String, state As String, zip As String
totalRecords = "=counta(Data!A:A)"
form1 = [List!E1] ' these are the locations of each form
form2 = [List!F1]
form3 = [List!G1]
[List!c1] = totalRecords
' Range("E10") = totalRecords
Dim mydate As Date
Set wsF = Sheets("Form")
mydate = Date
'wsF.Range("A9") = mydate
'wsF.Range("A9").NumberFormat = "[$-F800]dddd, mmmm dd,yyyyy" (Note [$-F800] is format long date)
'wsF.Range("A9").HorizontalAlignment = xlLeft
wsF.[A9] = mydate
wsF.[A9].NumberFormat = "dddd, mmmm dd,yyyyy"
wsF.[A9].HorizontalAlignment = xlLeft
StartRow = 1 'Prints from row 1
EndRow = [List!c1] 'Prints to last row controled by Cell "List C1"
'StartRow = InputBox("Enter first record to print.")(user chooses rows to print)
'EndRow = InputBox("Enter last record to print.")(user chooses rows to print)
'If StartRow > EndRow Then
'Msg = "ERROR" & vbCrLf & "The starting row must be less than the ending row!"
'MsgBox Msg, vbCritical, "Advanced Excel Training"
'End If
For i = StartRow To EndRow
Sheets("Form").Range("A11") = firstName & " " & lastName & vbCrLf & address1 & " " & address2 & vbCrLf & city & " " & state & vbCrLf & zip
Sheets("Form").Range("A13") = "Dear" & " " & firstName & ","
' the if statements choose which form to pass the document to be printed
If [List!A1] = 2 Then
Sheets("Form").Range("A15") = form1
End If
If [List!A1] = 3 Then
Sheets("Form").Range("A15") = form2
End If
If [List!A1] = 4 Then
Sheets("Form").Range("A15") = form3
End If
wsF.Shapes("Drop Down 2").OLEFormat.Object.Value = 1 ' this line resets the form box
'Sheets("Form").Range("A11") = firstName & " " & lastName & vbCrLf & address1 & vbCrLf & address2 & vbCrLf & city & vbCrLf & state & vbCrLf & zip
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1, _
Collate:=True, IgnorePrintAreas:=False
Next i
End Sub
Sub Read_Text_Files()
Dim sPath As String
Dim oPath, oFile, oFSO As Object
Dim r, iRow As Long
Dim wbImportFile As Workbook
Dim wsDestination As Worksheet
'Files location
sPath = "E:\Excel\"
Set wsDestination = ThisWorkbook.Sheets("Sheet1")
r = 1
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oPath = oFSO.GetFolder(sPath)
Application.ScreenUpdating = False
For Each oFile In oPath.Files
If LCase(Right(oFile.Name, 4)) = ".txt" Then
'open file to impor
Workbooks.OpenText Filename:=oFile.Path, Origin:=65001, StartRow:=1, DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, FieldInfo:=Array(1, 1), _
TrailingMinusNumbers:=True
Set wbImportFile = ActiveWorkbook
For iRow = 1 To wbImportFile.Sheets(1).UsedRange.Rows.Count
wbImportFile.Sheets(1).Rows(iRow).Copy wsDestination.Rows(r)
r = r + 1
Next iRow
wbImportFile.Close False
Set wbImportFile = Nothing
End If
Next oFile
End Sub
Click on the spin button and place on page. Now right click and Format Control. If this is changing the month set min to 1 and max to 12. |
Cell link is the cell that will change value. We can now use a IF statment to change months based on the value of (F1). In the cell you want the month to apprear use this as an example: =IF(F1=1,"January",IF(F1=2,"February",IF(F1=3,"March",IF(F1=4,"April", IF(F1=5,"May",IF(F1=6,"June",IF(F1=7,"July",IF(F1=8,"August", IF(F1=9,"September", IF(F1=10,"October",IF(F1=11,"November",IF(F1=12,"December",Error)))))))))))) |
This example teaches you how to apply an advanced filter to only display records that meet complex criteria.
When you use the Advanced Filter, you need to enter the criteria on the worksheet. Create a Criteria range(blue border below for illustration only) above your data set. Use the same column headers. Be sure there's at least one blank row between your Criteria range and data set.
To display the sales in the USA and in Qtr 4, execute the following steps.
1. Enter the criteria shown below on the worksheet.
2. Click any single cell inside the data set.
3. On the Data tab, in the Sort & Filter group, click Advanced.
4. Click in the Criteria range box and select the range A1:D2 (blue).
5. Click OK.
Now control this with a macro button. Notice the options to copy your filtered data set to another location and display unique records only (if your data set contains duplicates).
Result.
Application.Goto Reference:="R1C27"
ActiveCell.FormulaR1C1 = "lunch break"
ActiveCell.FormulaR1C1 = "=LEFT(RC[-4],5)" ( This says =left(Cell,5) or =Left(4cells to the left of the active cell,5) and 5 represents the number of digits to display. )
ActiveCell.Formula = "=if(A2=A1,0,""X"")"
ActiveCell.FormulaR1C1 = "=Trim(RC[1])" If this formula was in cell "A1" it would Trim 1 cell to the right. neg -1 would trim on cell to the left.
|
Sub NorthAmerica()
'
' NorthAmerica Macro
'
'
Range("BF3").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "North"
ActiveCell.Offset(0, -4).Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, 4).Range("A1").Select
Range(Selection, Selection.End(xlUp)).Select
Selection.FillDown
End Sub
Sub DateFillDown()
'
' DateFillDown Macro
'
'
'Application.ScreenUpdating = False
Range("G1").Select
Selection.Copy
Range("H1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Selection.Copy
Range("D1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Range("A1").Select
Sheets("Sheet1").Paste
Selection.Copy
Do
ActiveCell.Offset(1, -1).Range("A1").Select
If ActiveCell.Value = "" Then Exit Do
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveSheet.Paste
Loop
Application.CutCopyMode = False
ActiveWorkbook.Save
End Sub
Example: | ||
Unsorted | Sorted A-Z | Custom Sort |
|
|
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||
|
Here is another example of how we can delete a row based on criteria
Sub Prep_DeleteSE()
'
' Prep_DeleteSE Macro
'
'
Range("B2").Select
=WEEKNUM(A1,1) | Number of the week in the year, with a week beginning on Sunday |
=TEXT(A1,"DDD") | Shows Day of the Week (Mon... Tue...) |
=TEXT(A1,"MMM") | Shows what Month |
=TEXT(A1,"YYY") | Shows Year |
=Datedif(A1,Today(),"Y") | Number of "Y" Years "M" Months or "D" Days between today and A1 date |
=Networkday(A1,A10) | Counts only working days in a column of dates |
=Choose | This will choose the quarter that a month is in. In cell B1 insert this formula for cell A1. In cell A1 insert the date. Today’s date is “=now()” no quotes. Cell B1 report the quarter. =choose(month(A1),1,1,1,2,2,2,3,3,3,4,4,4) |
=Aggregate(Choice1,Choice2,Range) | Example: When would I use this formula? If we hide cell A2, cell A4 will still show the sum as 6. What you will see however is Cell A1 and A3 as 1 and 3 and cell A4 equaling 6. What we want to see is a sum of only the numbers that are visable. This is where you use =Aggregate(Choice,Choice,Range) in place of =sum(A1:A3) |
=Convert(cell,x,x) | Will convert many things. Each "X" is a drop down menu to choose from while you write the fomula. |
=Trim(A1) | This will remove or trim blank entries in front of letters. |
=Indirect( | See Last instance |
=Lookup(2,1/(B:B="Date"),C:C) | This looks up the word "Date" in column "B" and returns the cell value from column "C" Cell B10 contain "Date" Cell C10 contains the date 3/1/2013. The formula will return the date 3/1/2013. |
Time: | 1 Day is 24 hours or 1.0 - 1 hour is 1/24 of a day or 0.0416 |
Time format: | H:mm = hour and minutes in a 24 hour period - [H]:mm = hour and minutes which can exceed a 24 hour period |
Dates are numbers: | 1/1/1900 = 1 |
A | B | C | D | |
1 | 1 | Ted | Sam | Formula goes here |
2 | 2 | Ted | Will | |
3 | 2 | Ted | Will |
A | B | C | D | |
1 | 8 | 6 | 15 | Formula goes here |
2 | 2 | 2 | 25 | |
3 | 10 | 11 | 18 |
This uses Vlookup. The ISERROR is there because if it is not used you will get #N/A and can not work with this result.
This says IF VLOOKUP is True, False
So this is saying lookup the result of "VLOOKUP(C2,G:H,2,0)" shown in yellow which is SE
in range J:P
and the sum of B2 + 1 is the column reference, exactly.
One draw back to VLookup is that what you are looking up must be in the left most column so Alabama must be in column G of G:H.
To work around this problem use Index and Match.
Viewing the last entry in a column. Column A1 is a growing column of numbers or dates. In our result cell we want to view the last entry in that column. The formula would look like this:
=offset(A1,counta(A:A)-1,0)
Explained: “A1” is the start point, then “counta(A:A)-1,” counts down in column “A” until it finds a blank cell then moves up 1 from that blank cell. If you put -5 in this location the results
would be 5 cells above the blank cell in column “A”,0 Zero represents the number of columns to move to the right.
Sub Refresh_PivotTable_from_TableData()
Sheets("pt").Activate
' this is the sheet name where the Pivot Table is located
Dim pt As PivotTable
Set pt = ActiveSheet.PivotTables("PivotTable3")
' Set pt = ActiveSheet.PivotTables("PivotTable4")
' this refreshes 2 Pivot tables located on the same worksheet
pt.RefreshTable
MsgBox "Pivot table('s) have been successfully updated!"
End Sub
A | B | C | D | Result in D | |
1 | 1 | Chris | 3717 | =A1&B1&C1 | 1Chris3717 |
2 | 2 | Dan | 1861 | =A1& “ ”&B1&” “&C1 | 2 Dan 1861 |
3 |
Ctrl + | Shift + | ~ | General - Make a number a general number | |
Ctrl + | Shift + | 1 | Changes the number to a 2 decimal number. 1.2589 would become 1.25 | |
Ctrl + | Shift + | 2 | Changes a 24 hour format to 12 hour format and adds am /pm - or 13.50 becomes 1:50 PM | |
Ctrl + | Shift + | 3 | Changes Date format. 1/1/2013 becomes 1-Jan-13 | |
Ctrl + | Shift + | 4 | Changes Currency - 50 becomes $50.00 | |
Ctrl + | Shift + | 5 | Percent - .25 becomes 25% | |
Ctrl + | Shift + | 6 | Scientific - 50 becomes 5.00E+01 | |
Ctrl + | Shift + | 7 | Adds Border around highlighted cells | |
Ctrl + | Shift + | ( _ ) | Underscore - Removes border from highlighted cell('s) | |
Ctrl + | Shift + | ( + ) | Plus sign will add a row above selected row. | |
Ctrl + | Shift + | F | Will bring up the Format Cells Font dialog box. | |
Ctrl + | Z | Undo | ||
Ctrl + | Y | Redo | ||
Ctrl + | F2 | Preview Print output |
Where does a cell gets its data?
Ctrl + ; | Todays Date |
Ctrl + Shift | Current time |
Ctrl + T | Insert Table |
Ctrl + spacebar | Highlights Column |
Shift + Ctrl + spacebar | Highlights contiguous cells |
Ctrl + Shift + * | Active current range. Same as Shift + Ctrl + spacebar |
Alt + ; | Allow you to copy and paste with out showing hidden columns. Hide column B:B. Highlight column A and C. Press Alt + ; Copy and paste. Only columns A & C will be pasted. |
Alt + down arrow | Text only will show repeated name in a dropdown box. |
Ctrl and drag a tab | This will copy the entire tab. Click on TAB press Ctrl and drag to open area in bar. Release mouse. |
Right click in arrow box.
Here we can see that by right clicking on the arrows in the lower left corner will open a menu of your worksheets. This might help in navigating to a sheet that you can not see across the bottom of your current view. |
Sub Copy_ActiveSheet_2()
'Working in Excel 2000-2013
Dim fname As Variant
Dim NewWb As Workbook
Dim FileFormatValue As Long
'Check the Excel version
If Val(Application.Version) < 9 Then Exit Sub
If Val(Application.Version) < 12 Then
'Only choice in the "Save as type" dropdown is Excel files(xls)
'because the Excel version is 2000-2003
fname = Application.GetSaveAsFilename(InitialFileName:="", _
filefilter:="Excel Files (*.xls), *.xls", _
Title:="This example copies the ActiveSheet to a new workbook")
If fname <> False Then
'Copy the ActiveSheet to new workbook
ActiveSheet.Copy
Set NewWb = ActiveWorkbook
'We use the 2000-2003 format xlWorkbookNormal here to save as xls
NewWb.SaveAs fname, FileFormat:=-4158, CreateBackup:=False
NewWb.Close False
Set NewWb = Nothing
End If
Else
'Give the user the choice to save in 2000-2003 format or in one of the
'new formats. Use the "Save as type" dropdown to make a choice,Default =
'Excel Macro Enabled Workbook. You can add or remove formats to/from the list
fname = Application.GetSaveAsFilename(InitialFileName:="", filefilter:= _
" Excel Macro Free Workbook (*.csv), *.csv," & _
" Excel Macro Free Workbook (*.txt), *.txt," & _
" Excel Macro Free Workbook (*.xlsx), *.xlsx," & _
" Excel Macro Enabled Workbook (*.xlsm), *.xlsm," & _
" Excel 2000-2003 Workbook (*.xls), *.xls," & _
" Excel Binary Workbook (*.xlsb), *.xlsb", _
FilterIndex:=2, Title:="This example copies the ActiveSheet to a new workbook")
'Find the correct FileFormat that match the choice in the "Save as type" list
If fname <> False Then
Select Case LCase(Right(fname, Len(fname) - InStrRev(fname, ".", , 1)))
' Case "csv": FileFormatValue = 6
Case "txt": FileFormatValue = -4158
' Unmark these for other file formats This macro set to save as .txt
' Case "xls": FileFormatValue = 56
' Case "xlsx": FileFormatValue = 51
' Case "xlsm": FileFormatValue = 52
' Case "xlsb": FileFormatValue = 50
' Case Else: FileFormatValue = 0
End Select
'Now we can create/Save the file with the xlFileFormat parameter
'value that match the file extension
If FileFormatValue = 0 Then
MsgBox "Sorry, unknown file extension"
Else
'Copies the ActiveSheet to new workbook
ActiveSheet.Copy
Set NewWb = ActiveWorkbook
'Save the file in the format you choose in the "Save as type" dropdown
NewWb.SaveAs fname, FileFormat:= _
FileFormatValue, CreateBackup:=False
NewWb.Close False
Set NewWb = Nothing
End If
End If
End If
End Sub
Macro delivers current time to Cell A1
In cell B1 type 1:00
In cell C1 type "=A1+B1" This will give you a range of current time plus one hour for tracking lunch times as an example.
=Proper(A1) | Proper will capitolize the letters so that: dan carpenter would be Dan Carpenter |
=Trim(A1) | Trim will remove extra spaces in front or at end or double spaces between letters |
=Proper(Trim(A1) | Combine these to make a list of name consistant and easier to read. |
Colors and Pictures
Themes, On the Page Layout tab choose themes. This will reset the main color palate.
Pictures, From the insert tab insert a picture. Now click on the picture. On the Picture Tools Format tab click on remove background. Check out all the other things you can do.
Private Sub Worksheet_Change(ByVal Target As Range) ' If Not Intersect(Target, Range("H12:H14")) Is Nothing Then lRed = Abs(Range("H12").Value) Mod 256 lGreen = Abs(Range("H13").Value) Mod 256 lBlue = Abs(Range("H14").Value) Mod 256 Range("K12").Interior.Color = RGB(lRed, lGreen, lBlue) ' End If End Sub |
|
NOTE To view the dates as numbers, select the cell and click Cells on the Format menu. Click the Number tab, and then click Number in the Category box.
A | B | C | Note that Column C needs to be formatted . - - - Custom / mm:ss | |
1 | 120 | =A1/86400 | 02:00 | |
2 | ||||
3 | Seconds | Formula | Result |
Sub clearfilters() ' ' clearfilters Macro ActiveSheet.ShowAllData ' End Sub |
|
This will remove or clear a filter from a specific column in this case column 2 (field 2) | |
Sub RemoveFilter() strAddress = ActiveCell.CurrentRegion.Address ActiveSheet.Range(strAddress).AutoFilter Field:=2 End Sub |
Sub step_A()
'
' step_A Macro
'
'
Application.ScreenUpdating = False
ActiveSheet.Range("E2", ActiveSheet.Range("E2").End(xlDown)).Select
Selection.Clear
Range("A1").CurrentRegion.Select
Selection.Copy
Range("E1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("db").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("db").Sort.SortFields.Add Key:=Range("E2") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("db").Sort
.SetRange Range("E1").CurrentRegion
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ActiveSheet.Range("$E$1").CurrentRegion.RemoveDuplicates Columns:=Array(1, 3), Header _
:=xlYes
Range("D1").Select
End Sub
Select | VBA Coding |
---|---|
Entire Table | ActiveSheet.ListObjects("Table1").Range.Select |
Table Header Row | ActiveSheet.ListObjects("Table1").HeaderRowRange.Select |
Table Data | ActiveSheet.ListObjects("Table1").DataBodyRange.Select |
Third Column | ActiveSheet.ListObjects("Table1").ListColumns(3).Range.Select |
Third Column (Data Only) | ActiveSheet.ListObjects("Table1").ListColumns(3).DataBodyRange.Select |
Select Row 4 of Table Data | ActiveSheet.ListObjects("Table1").ListRows(4).Range.Select |
Select 3rd Heading | ActiveSheet.ListObjects("Table1").HeaderRowRange(3).Select |
Select Data point in Row 3, Column 2 | ActiveSheet.ListObjects("Table1").DataBodyRange(3, 2).Select |
Subtotals | ActiveSheet.ListObjects("Table1").TotalsRowRange.Select |
Select | VBA Coding |
---|---|
Insert A New Column 4 | ActiveSheet.ListObjects("Table1").ListColumns.Add Position:=4 |
Insert Column at End of Table | ActiveSheet.ListObjects("Table1").ListColumns.Add |
Insert Row Above Row 5 | ActiveSheet.ListObjects("Table1").ListRows.Add (5) |
Add Row To Bottom of Table | ActiveSheet.ListObjects("Table1").ListRows.Add AlwaysInsert:= True |
Add Totals Row | ActiveSheet.ListObjects("Table1").ShowTotals = True |
Sub Selectmem()
ActiveSheet.ListObjects("Table2").ListRows(ActiveCell.Row).Range.Select
End Sub
Sub sortitout()
'
' sortitout Macro
'
'
Range("A1").Select
Do
ActiveCell.Offset(0, 1).Range("A1").Select
If ActiveCell.Value = "Stop" Then Exit Do
ActiveCell.EntireColumn.Select
ActiveWorkbook.Worksheets("Sheet5").sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet5").sort.SortFields.Add Key:=ActiveCell.EntireColumn, _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("Sheet5").sort
.SetRange ActiveCell.EntireColumn
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Loop
End Sub
Sub deldups()
'
'
'
Range("A1").Select
'ActiveSheet.Range("$A$1:$A$1403").RemoveDuplicates Columns:=1, Header:=xlNo
Do
ActiveCell.Offset(0, 1).Range("A1").Select
If ActiveCell.Value = "Stop" Then Exit Do
' ActiveSheet.ActiveCell.EntireColumn.RemoveDuplicates Columns:=1, Header:=xlNo
ActiveCell.EntireColumn.RemoveDuplicates Columns:=1, Header:=xlNo
Loop
End Sub
Sub coppy()
'
'
End Sub
Sub column()
'
' column Macro
'
Range("A1").Select
ActiveCell.Offset(0, 1).Range("A1").Select
'
Do
Range(ActiveCell, ActiveCell.End(xlDown)).Select
Selection.Cut
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Paste
Range(ActiveCell, ActiveCell.End(xlUp)).Select
Selection.End(xlToRight).Select
If ActiveCell.Value = "Stop" Then Exit Do
Loop
End Sub
Sub right()
'
' right Macro
'
'
Range("A1").Select
Selection.End(xlToRight).Select
End Sub
Using an external workbook.
=SUM([Budget.xlsx]Annual!C10:C25)
More information click here.