thereseexceljakubiak
New Member
Hi! So this code below, works awesomely- thanks to Excel Ninja! - but I now i have modified the data table so all the columns are screwed up!
BEFORE:
ALL IN COLUMN B:
Date
Item1
Item2
Item3
NextDate
Item1
Item2
Item3
Goal was to find a specific Date, then find a specific Item under that date and insert a row with User Input going to the cell in column B. The cell in Column C just copied down the formula from above.
NOW:
COL B
has formula that needs to be copied down
COL C -
Date
Same Date above
Same Date above
Same Date above
Same Date above
NextDate
Same Date above
Same Date above
Same Date above
Same Date above
Col E:
Item1
Item2
Item3
Item4
Item1
Item2
Item3
Item4
Item1
Item2
Item3
Item4
Goal is to find a specific Date (in col C) AND specific Item (in col E), then insert a NEW ROW with User Input going to the cell (in column E). The cell in Column B just copies down the formula from above. The cell in Column C should just equal the date above.
Here is the ORIGINAL MACRO:
[pre]
[/pre]
BEFORE:
ALL IN COLUMN B:
Date
Item1
Item2
Item3
NextDate
Item1
Item2
Item3
Goal was to find a specific Date, then find a specific Item under that date and insert a row with User Input going to the cell in column B. The cell in Column C just copied down the formula from above.
NOW:
COL B
has formula that needs to be copied down
COL C -
Date
Same Date above
Same Date above
Same Date above
Same Date above
NextDate
Same Date above
Same Date above
Same Date above
Same Date above
Col E:
Item1
Item2
Item3
Item4
Item1
Item2
Item3
Item4
Item1
Item2
Item3
Item4
Goal is to find a specific Date (in col C) AND specific Item (in col E), then insert a NEW ROW with User Input going to the cell (in column E). The cell in Column B just copies down the formula from above. The cell in Column C should just equal the date above.
Here is the ORIGINAL MACRO:
[pre]
Code:
Sub AddAItem()
Dim strReply As String
Dim lReply As Long
Dim LastRow As Long
Dim StartCell As Range
Dim vFound As Range
Dim newTerm As String
MsgBox ("This macro will add a New Item to the Item column B. It will find a row with your exact item and insert a row beneath ALL instances. Once the macro executes, an Undo will not work. To CANCEL, please press CANCEL on the next screen.")
With ActiveSheet
LastRow = Cells(Rows.Count, "B").End(xlUp).Row
End With
'Prompt user for what day/value to look for to start at
Set StartCell = Range("B:B").Find(InputBox("What Date would you like the New Rows to Start From? E.g., 10/1/2012"))
'Adjust start cell to be something in col B
If StartCell Is Nothing Then
Set StartCell = Range("B6")
Else
Set StartCell = StartCell.Offset(0, 1)
End If
'Break this out to separate line, check for null
strReply = InputBox("Please Enter the Item to Search For. The New Item will be inserted after this row:")
If strReply = vbNullString Then
lReply = MsgBox("An executed macro cannot be Undone. Do you wish to cancel?", vbYesNo)
If lReply = vbYes Then Exit Sub
End If
Set vFound = Range(StartCell, Cells(LastRow, "B")).Find(What:=strReply, _
After:=StartCell, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
newTerm = InputBox("Please Enter New Item to add:")
If Not vFound Is Nothing Then
Application.ScreenUpdating = False
vStart = vFound.Address
Do
Rows(vFound.Row + 1).Insert (xlShiftDown)
Cells(vFound.Row + 1, "B").Value = newTerm
Cells(vFound.Row + 1, "C").FormulaR1C1 = "=sum(RC4:RC40)"
Set vFound = Cells.FindNext(vFound)
Loop Until vFound.Address = vStart
Application.ScreenUpdating = True
Else
MsgBox ("Not Found")
End If
End Sub