Help with macro code

Frank3923

Board Regular
Joined
Jan 20, 2003
Messages
244
I have enclosed some code for a macro, I now have a need to have several sTxts to work with instead of one.
I tried a couple of variations,

example - sTxt = "Saturday" Or "Friday", sTxt = "Friday" or "Saturday"

But when I attempt to run, I am getting a mismatch error msg.


Any suggestions, or help in how I could accomplish this, would be appreciated.




.............................................................
Sub FindEm2()
Dim tempcell As Range, Found As Range, sTxt
sTxt = "Saturday"
With Range("E1:E600")

For Each cell In Range("E1:E600")

Set tempcell = .Cells.Find(What:=sTxt)
If tempcell Is Nothing Then
MsgBox prompt:="Not found"
Exit Sub
Else
tempcell.Offset(0, 0).Resize(1).Cut Destination:=tempcell.Offset(2, -2)
Set Found = tempcell
End If
Do
On Error Resume Next
Set tempcell = .Cells.FindNext(After:=Found)
On Error GoTo 0
If Found.Row >= tempcell.Row And Found.Column >= tempcell.Column Then Exit Do
tempcell.Offset(0, 0).Resize(1).Cut Destination:=tempcell.Offset(2, -2)
Set Found = tempcell
Loop
Next cell
End With
Application.CutCopyMode = False
End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
HAve you considered changing to an InputBox to select which txt you want ??
Code:
Sub FindEm2()
Dim tempcell As Range, Found As Range, sTxt
sTxt = InputBox("Please Type in the Day you want?", "Day Title")
With Range("E1:E600")

For Each cell In Range("E1:E600")

Set tempcell = .Cells.Find(What:=sTxt)
If tempcell Is Nothing Then
MsgBox prompt:="Not found"
Exit Sub
Else
tempcell.Offset(0, 0).Resize(1).Cut Destination:=tempcell.Offset(2, -2)
Set Found = tempcell
End If
Do
On Error Resume Next
Set tempcell = .Cells.FindNext(After:=Found)
On Error GoTo 0
If Found.Row >= tempcell.Row And Found.Column >= tempcell.Column Then Exit Do
tempcell.Offset(0, 0).Resize(1).Cut Destination:=tempcell.Offset(2, -2)
Set Found = tempcell
Loop
Next cell
End With
Application.CutCopyMode = False
End Sub
 
Upvote 0
a Inputbox would work. However, I really only have a total of 3, that I work with, and that way, I would have to do any input while running the sub.

Thank you for your ideas and assistance.
 
Upvote 0

Forum statistics

Threads
1,224,525
Messages
6,179,317
Members
452,905
Latest member
deadwings

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top