Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub InsertDate()
- Dim ts As Date
- With Selection
- .Value = Date
- '.NumberFormat = "yyyy-mm-dd h:mm:ss AM/PM”"
- End With
- End Sub
- Sub NewSale()
- '
- ' NewSale Macro
- '
- ' Keyboard Shortcut: Ctrl+n
- ' Disable screen updating. From https://www.reddit.com/r/excel/comments/dqmhl1/two_months_ago_i_knew_nothing_today_this_is/f6aat3h/?context=3
- Application.ScreenUpdating = False
- Application.EnableEvents = False
- Dim blnInSalesTable As Boolean
- OldRow = ActiveCell.Address ' Get current cell's address
- ' Is cursor in Sales table?
- With Selection
- blnInSalesTable = Not Intersect(ActiveCell, [Sales]) Is Nothing
- End With
- Application.Goto reference:="[is.xlsm]IS!Sales[#Totals]" ' Move cursor to Totals row (i.e., just below bottom of table)
- Application.CutCopyMode = False
- ' Insert new row above current.
- ' CopyOrigin necessary because My base price/item column wasn't formatted with background fill at table creation
- ActiveCell.EntireRow.Insert CopyOrigin
- If blnInSalesTable Then ' If cursor was in Sales table at macro start,
- NewRow = ActiveCell.Address ' Get current cell's address.
- Range(OldRow).EntireRow.Copy Range(NewRow).EntireRow ' Copy cursor's row over current row
- End If
- ' [Table[ColumnName]].Column] syntax from https://stackoverflow.com/questions/18811431/refer-to-excel-cell-in-table-by-header-name-and-row-number
- ActiveSheet.Cells(ActiveCell.Row, [Sales[Date]].Column).Select ' Go to Date column
- InsertDate
- If blnInSalesTable Then ' If cursor was in Sales table at macro start,
- ActiveSheet.Cells(ActiveCell.Row, [Sales[Serial '#]].Column).ClearContents ' Blank Serial # column
- ActiveSheet.Cells(ActiveCell.Row, [Sales[Qty]].Column).ClearContents ' Blank Qty column
- ActiveSheet.Cells(ActiveCell.Row, [Sales[Sales Tax/VAT]].Column).ClearContents ' Blank Sales Tax/VAT column
- ActiveSheet.Cells(ActiveCell.Row, [Sales[Shipping credit]].Column).ClearContents ' Blank Shipping credit column
- ActiveSheet.Cells(ActiveCell.Row, [Sales[Order '#]].Column).ClearContents ' Blank Order # column
- ActiveSheet.Cells(ActiveCell.Row, [Sales[Transaction '#]].Column).ClearContents ' Blank Transaction # column
- ActiveSheet.Cells(ActiveCell.Row, [Sales[Market]].Column).ClearContents ' Blank Market column
- ActiveSheet.Cells(ActiveCell.Row, [Sales[Payment]].Column).ClearContents ' Blank Payment column
- ActiveSheet.Cells(ActiveCell.Row, [Sales[To]].Column).ClearContents ' Blank To column
- ActiveSheet.Cells(ActiveCell.Row, [Sales[Shipping]].Column).ClearContents ' Blank Shipping column
- ActiveSheet.Cells(ActiveCell.Row, [Sales[Combined?]].Column).ClearContents ' Blank Combined? column
- CenterOnCell ActiveSheet.Cells(ActiveCell.Row, [Sales[Qty]].Column) ' center on Qty. Else,
- Else
- ActiveSheet.Cells(ActiveCell.Row, [Sales[Total fees]].Column).FillDown ' Necessary because column and formula were added after table's creation
- CenterOnCell ActiveSheet.Cells(ActiveCell.Row, [Sales[Item]].Column) ' center on Item
- End If
- Application.CutCopyMode = False
- ' Reenable screen updating
- Application.EnableEvents = True
- Application.ScreenUpdating = True
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement