HELP - Error 91 with recorded macro

pattyrick55

New Member
Joined
Aug 21, 2015
Messages
2
Hey so i am trying to make a macro that executes the find next -> replace all path. Highlight a column and replace certain values in the column with a different value. i have no experience with VBA so i used the record a macro button in excel. The resulting macro gives me an error 91 when i try to run it. New to the forums here so i don't know if there is a way to attach code properly but i will just copy and paste.

Columns("L:L").Select
Selection.Find(What:="-1707687036", After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Selection.Replace What:="-1707687036", Replacement:="2", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Find(What:="-1672939979", After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Selection.Replace What:="-1672939979", Replacement:="4", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Find(What:="-84018325", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Selection.Replace What:="-84018325", Replacement:="1", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Find(What:="1246160210", After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Selection.Replace What:="1246160210", Replacement:="3", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Find(What:="1690209903", After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Selection.Replace What:="1690209903", Replacement:="5", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hey,

And welcome to the forum.

I assume that what you look for are numbers, not figures saved as text (otherwise put long numbers into "-1234567")

Code:
Sub Test()
Dim FindCell as Range

[COLOR=#008000]'Maybe reduce the range from ("L:L") to ("L1:L1000") to get the macro run quicker[/COLOR]

For each FindCell in Range("L:L")

If FindCell=-84018325 then FindCell.value=1
End if
If FindCell=-1707687036 then FindCell.value=2 
End i
If FindCell1246160210 then FindCell.value=3
End if
If FindCell=-1672939979 then FindCell.value=4
End if
If FindCell=1690209903 then FindCell.value=4
End if


Next Findcell
End sub
 
Upvote 0
Hey,

And welcome to the forum.

I assume that what you look for are numbers, not figures saved as text (otherwise put long numbers into "-1234567")

Code:
Sub Test()
Dim FindCell as Range

[COLOR=#008000]'Maybe reduce the range from ("L:L") to ("L1:L1000") to get the macro run quicker[/COLOR]

For each FindCell in Range("L:L")

If FindCell=-84018325 then FindCell.value=1
End if
If FindCell=-1707687036 then FindCell.value=2 
End i
If FindCell1246160210 then FindCell.value=3
End if
If FindCell=-1672939979 then FindCell.value=4
End if
If FindCell=1690209903 then FindCell.value=4
End if


Next Findcell
End sub



Thanks man, just learning how powerful excel can be. excited to see what i can do with the database ive been put in charge to import!
Giving this a shot later tonight, didn't expect such a prompt response.
cheers, and have a good day!
 
Upvote 0

Forum statistics

Threads
1,215,836
Messages
6,127,173
Members
449,368
Latest member
JayHo

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