Hi! I'm trying to copy a range of cells to a second sheet and then delete the row from the first sheet. It seems like it should be pretty simple but the code is throwing an unknown error and highlighting the line "Sheets("Sheet1").Range(cell1, cell2).Copy"
Any ideas why this would be happening?
As a side note, ideally this code would paste into the first empty row in sheet 2, but I'm doing things one step at a time and want to get this first basic step debugged first.
Any ideas why this would be happening?
As a side note, ideally this code would paste into the first empty row in sheet 2, but I'm doing things one step at a time and want to get this first basic step debugged first.
Code:
Public Sub FindTag()
'Creating an input box
Dim myValue As Variant
myValue = InputBox("Enter Tag being found")
'Searching for the input to delete
Dim x As String, firstCell As Variant, secCell As Variant, NextRow As Variant
Dim Found As Boolean
' Select first line of data.
Range("A2").Select
' Set search variable value.
x = myValue
' Set Boolean variable "found" to false.
Found = False
' Set Do loop to stop at empty cell.
Do Until IsEmpty(ActiveCell)
' Check active cell for search value.
If ActiveCell.Value = x Then
Found = True
Exit Do
End If
' Step down 1 row from present location.
ActiveCell.Offset(1, 0).Select
Loop
' Check for found.
If Found = True Then
Column = Mid(ActiveCell.Address, 4, 1)
cell1 = "A" & Column
cell2 = "M" & Column
'Copy the data
Sheets("Sheet1").Range(cell1, cell2).Copy
'Activate the destination worksheet
Sheets("Sheet2").Activate
'Select the target range
Range("A2").Select
'Paste in the target destination
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveCell.EntireRow.Delete
MsgBox "Tag copied!"
Else
MsgBox "Value not found"
End If
End Sub