Radnanigan
New Member
- Joined
- Sep 18, 2018
- Messages
- 2
Hello,
VBA newbie here. The goal of this script is to locate missing data, take user input, and copy a subsequent row of data on another sheet. When I test the script by inputting the missing inventory, I am facing two problems:
I suspect the 1004 error is being caused by the "Worksheets("Data").Activate line but I cannot understand why. Can someone please explain?
Thanks for your help!
Sub MissingInput()
Dim UserInputInv As Variant
Dim MissingInv As Variant
Dim MissingDate As Date
Dim DateRange As Range
Worksheets("User Input").Activate
Set DateRange = Range("B16:B128")
DateRange.Select
For Each Cell In Range("B16:B128")
If Cell.Value = "" And Cell.Offset(RowOffset:=0, ColumnOffset:=-1).Value < [Today()] Then
Cell.Select
ActiveCell.Offset(RowOffset:=0, ColumnOffset:=-1).Select
Cell.Value = MissingDate
Do While True
UserInputInv = InputBox("Enter inventory for " & MissingDate)
If IsNumeric(UserInputInv) Then
MissingInv = CDbl(UserInputInv)
Exit Do
End If
Loop
ActiveCell.Offset(0, 1).Value = MissingInv
Worksheets("Data").Activate
Range("A16:A128").Find (MissingDate)
Cell.Select
Range(ActiveCell.Offset(-1, 2), ActiveCell.Offset(-1, 3)).Select
Selection.Copy
ActiveCell.Offset(0, 2).PasteSpecial (xlPasteValues)
End If
Next
Worksheets("User Input").Activate
Range("C11").Select
End Sub
VBA newbie here. The goal of this script is to locate missing data, take user input, and copy a subsequent row of data on another sheet. When I test the script by inputting the missing inventory, I am facing two problems:
- The MissingDate variable becomes "12:00 am" for its respective cell on the "User Input" page (least important problem).
- The 1004 error occurs at the second Cell.Select section and does not allow the script to finish the copying function at the end of the For loop.
I suspect the 1004 error is being caused by the "Worksheets("Data").Activate line but I cannot understand why. Can someone please explain?
Thanks for your help!
Sub MissingInput()
Dim UserInputInv As Variant
Dim MissingInv As Variant
Dim MissingDate As Date
Dim DateRange As Range
Worksheets("User Input").Activate
Set DateRange = Range("B16:B128")
DateRange.Select
For Each Cell In Range("B16:B128")
If Cell.Value = "" And Cell.Offset(RowOffset:=0, ColumnOffset:=-1).Value < [Today()] Then
Cell.Select
ActiveCell.Offset(RowOffset:=0, ColumnOffset:=-1).Select
Cell.Value = MissingDate
Do While True
UserInputInv = InputBox("Enter inventory for " & MissingDate)
If IsNumeric(UserInputInv) Then
MissingInv = CDbl(UserInputInv)
Exit Do
End If
Loop
ActiveCell.Offset(0, 1).Value = MissingInv
Worksheets("Data").Activate
Range("A16:A128").Find (MissingDate)
Cell.Select
Range(ActiveCell.Offset(-1, 2), ActiveCell.Offset(-1, 3)).Select
Selection.Copy
ActiveCell.Offset(0, 2).PasteSpecial (xlPasteValues)
End If
Next
Worksheets("User Input").Activate
Range("C11").Select
End Sub