Combreal

AddRow.vba

Apr 13th, 2021 (edited)
1,152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --- x8 centers
  2. If Cells(Target.Row, 5).Value <= Cells(Target.Row, 6).Value And Not IgnoreAlert Then 'And Len(Target) <= 4
  3.  
  4. --------stock
  5. Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  6.     Application.OnKey "%{UP}", "addRow"
  7. End Sub
  8.  
  9. ------- module 2
  10. Public IgnoreAlert As Boolean
  11.  
  12. Sub addRow()
  13.     Dim stock
  14.     Set stock = Sheets("Stock")
  15.     Dim tTotalRows As Long
  16.     Dim RowPos As Integer
  17.     Dim ws As Worksheet
  18.    
  19.     IgnoreAlert = True
  20.    
  21.     tTotalRows = stock.Cells.SpecialCells(xlLastCell).Row + 1
  22.     tTotalRows = stock.Range("A" & tTotalRows).End(xlUp).Row
  23.    
  24.     RowPos = ActiveCell.Row
  25.     ActiveCell.EntireRow.Copy
  26.     Range(ActiveCell, ActiveCell).EntireRow.Insert Shift:=xlDown
  27.     Application.CutCopyMode = False
  28.    
  29.     Application.ScreenUpdating = False
  30.     For Each ws In ActiveWorkbook.Worksheets
  31.         If Not ws.Name = "Stock" Then
  32.             ws.Activate
  33.             Cells(RowPos, 1).EntireRow.Copy
  34.             Cells(RowPos, 1).EntireRow.Insert Shift:=xlDown
  35.             Application.CutCopyMode = False
  36.         End If
  37.     Next ws
  38.     Application.ScreenUpdating = True
  39.    
  40.     Worksheets("Stock").Activate
  41.     Range(Cells(2, 5), Cells(4, 5)).AutoFill Destination:=Range(Cells(2, 5), Cells(tTotalRows, 5)), Type:=xlFillDefault
  42.     Range(Cells(2, 8), Cells(4, 8)).AutoFill Destination:=Range(Cells(2, 8), Cells(tTotalRows, 8)), Type:=xlFillDefault
  43.     IgnoreAlert = False
  44. End Sub
Add Comment
Please, Sign In to add comment