This code prompts the user to select how many rows they want to add and then subsequently copies the formulas down into the newly added rows. I does everything I want except one thing: I want today's date to be inserted in the correct cells within each newly inserted row. Column B contains the cells where I want today's date to be entered.
For example, if the user adds two rows (rows 7-8) using my macro, I want today's date to automatically appear in B7 and B8. Tomorrow when the user wants to add three more rows (rows 9-11), rows 7-8 still have yesterday's date when the macro was ran and the new rows have today's date.
I hope that makes sense. I would appreciate any help out there.
Sub InsertRowsAndFillFormulas()
Sheet1.Unprotect Password:="p@ssword9"
Dim vRows As Long
Dim sht As Worksheet, shts() As String, i As Long
Cells(TotalCount + 6, 6).Select 'I know I have 5 header rows
ActiveCell.EntireRow.Select
vRows = _
Application.InputBox(prompt:= _
"How many rows do you want to add?", Title:="Add Rows", _
Default:=1, Type:=1) 'type 1 is number
If vRows = False Then Exit Sub
'if you just want to add cells and not entire rows
' then delete ".EntireRow" in the following line
ReDim shts(1 To Worksheets.Application.ActiveWorkbook. _
Windows(1).SelectedSheets.Count)
i = 0
'insert rows on grouped worksheets
' rev. 2001-01-17 Gary Brown
For Each sht In _
Application.ActiveWorkbook.Windows(1).SelectedSheets
Sheets(sht.Name).Select
i = i + 1
shts(i) = sht.Name
Selection.Resize(rowsize:=2).Rows(2).EntireRow. _
Resize(rowsize:=vRows).Insert Shift:=xlDown
Selection.AutoFill Selection.Resize(rowsize:=vRows + 1), _
xlFillDefault
On Error Resume Next
Selection.Offset(1).Resize(vRows).EntireRow. _
SpecialCells(xlConstants).ClearContents
Next sht
Worksheets(shts).Select
Sheet1.Protect Password:="p@ssword9"
End Sub
For example, if the user adds two rows (rows 7-8) using my macro, I want today's date to automatically appear in B7 and B8. Tomorrow when the user wants to add three more rows (rows 9-11), rows 7-8 still have yesterday's date when the macro was ran and the new rows have today's date.
I hope that makes sense. I would appreciate any help out there.
Sub InsertRowsAndFillFormulas()
Sheet1.Unprotect Password:="p@ssword9"
Dim vRows As Long
Dim sht As Worksheet, shts() As String, i As Long
Cells(TotalCount + 6, 6).Select 'I know I have 5 header rows
ActiveCell.EntireRow.Select
vRows = _
Application.InputBox(prompt:= _
"How many rows do you want to add?", Title:="Add Rows", _
Default:=1, Type:=1) 'type 1 is number
If vRows = False Then Exit Sub
'if you just want to add cells and not entire rows
' then delete ".EntireRow" in the following line
ReDim shts(1 To Worksheets.Application.ActiveWorkbook. _
Windows(1).SelectedSheets.Count)
i = 0
'insert rows on grouped worksheets
' rev. 2001-01-17 Gary Brown
For Each sht In _
Application.ActiveWorkbook.Windows(1).SelectedSheets
Sheets(sht.Name).Select
i = i + 1
shts(i) = sht.Name
Selection.Resize(rowsize:=2).Rows(2).EntireRow. _
Resize(rowsize:=vRows).Insert Shift:=xlDown
Selection.AutoFill Selection.Resize(rowsize:=vRows + 1), _
xlFillDefault
On Error Resume Next
Selection.Offset(1).Resize(vRows).EntireRow. _
SpecialCells(xlConstants).ClearContents
Next sht
Worksheets(shts).Select
Sheet1.Protect Password:="p@ssword9"
End Sub