Syntax error

erimhast83

New Member
Joined
Jan 3, 2018
Messages
14
Can anyone spot the error in my code causing the syntax error? I am trying to use a loop to replace all blank cells in column D with the word homeless until column B has a blank cell and then the loop will end.


Do Until IsEmpty(ActiveCell.Offset(-2, 0))

ActiveCell.Replace What:="", Replacement:="Homeless", LookAt:=xlPart,
SearchOrder:=xlByColumns, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Cells.FindNext(After:=ActiveCell).Activate
Loop
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Do you want to give us a hint about which line(s) that VBA complains about?

Or is that part of the test? <wink>

Well, I do see an obvious syntax error: missing underbar after xlPart in the ActiveCell.Replace line.

I don't know if you copy-and-pasted the text from VBA, or if you retyped it. Certainly, copy-and-paste is the right way to do it.</wink>
 
Last edited:
Upvote 0
Along with what joeu2004 has said
Your first line of code does not match your description. It's currently looking 2 rows above the active cell, not 2 columns to the left.
 
Upvote 0
ActiveCell.Replace What:="", Replacement:="Homeless", LookAt:=xlPart,
SearchOrder:=xlByColumns, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False


I did copy and paste from VBA and adding the _ after xlpart did not help :(.




Do you want to give us a hint about which line(s) that VBA complains about?

Or is that part of the test? <wink>

Well, I do see an obvious syntax error: missing underbar after xlPart in the ActiveCell.Replace line.

I don't know if you copy-and-pasted the text from VBA, or if you retyped it. Certainly, copy-and-paste is the right way to do it.</wink>
 
Upvote 0
I did copy and paste from VBA and adding the _ after xlpart did not help

I suspect you applied my suggestion literally, and put the underscore in the wrong place.

My bad! I should have provided a concrete example.

Rich (BB code):
Do Until IsEmpty(ActiveCell.Offset(-2, 0))
   ActiveCell.Replace What:="", Replacement:="Homeless", LookAt:=xlPart, _
       SearchOrder:=xlByColumns, MatchCase:=False, SearchFormat:=False, _
       ReplaceFormat:=False
   Cells.FindNext(After:=ActiveCell).Activate
Loop

Without the underscore after xlPart as shown, VBA highlights the 3 lines from ActiveCell.Replace through ReplaceFormat in red, indicating a syntax error.

With the underscore after xlPart as shown, VBA accepts the syntax.

Note that I am only answering your syntax question.

I did not bother to analyze the code to see if it does what you might expect.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,045
Messages
6,122,840
Members
449,096
Latest member
Erald

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