Eurekaonide
Active Member
- Joined
- Feb 1, 2010
- Messages
- 422
Hi
I'm trying to use an input box to find a week number in row 2 of a worksheet, but it keeps coming back with either mismatch errors or with block errors. My code so far is below which looks like it finds the cell but I need it to then select the entire column and copy and paste it to remove the formulas, ready for the next input.
I set it as a variant because although the majority of weeks are number (i.e 45. on occasions they have to repeat in order to split out the months so I will have a 50a and 50b) and thought Variant would allow numbers and text.
Eventually I'd like this to loop through each visible worksheet in the workbook if possible. Rows will always be row 2.
I'm trying to use an input box to find a week number in row 2 of a worksheet, but it keeps coming back with either mismatch errors or with block errors. My code so far is below which looks like it finds the cell but I need it to then select the entire column and copy and paste it to remove the formulas, ready for the next input.
I set it as a variant because although the majority of weeks are number (i.e 45. on occasions they have to repeat in order to split out the months so I will have a 50a and 50b) and thought Variant would allow numbers and text.
Eventually I'd like this to loop through each visible worksheet in the workbook if possible. Rows will always be row 2.
VBA Code:
Sub Test_InputBox()
Dim i As Variant
i = InputBox("Enter Week Number to find")
With ActiveSheet.Rows("2:2").Select
Set Row = Selection.Find(What:=i, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
ActiveCell.EntireColumn.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
cutcopypaste = False
End With
If cell Is Nothing Then
MsgBox ("Week is not found")
End If
End Sub