Compile error: Expected: To

Dholt01

New Member
Joined
Jul 21, 2017
Messages
3
Hi - I'm a novice user running into a problem I've spent a few days trying to correct. I'm using the following code to run through a worksheet and if the there is data in a cell in column O I need to clear contents of the corresponding cell in column H but I keep getting a compile error... the problem seems to be with the "For deleterate" statement. Any suggestions? Thanks in advance

Sub deleterate()


' disable excel fetures
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
Application.ScreenUpdating = False

'variables
Dim deleterate As Long
Dim ws As Worksheet

' set object
Set ws = Sheets("Import file")


' loop through the data to find the $$ amounts in column o

For deleterate = ws.Range("O" & Rows.count).End(xlUp).Row


' indentify values in O which have value

If ws.Range("O" & deleterate).Value <> 0 Then
ws.Cells(deleterate, 8).ClearContents
End If

' move to next cell in the range

Next deleterate

' enable excel features

Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
Application.ScreenUpdating = True



End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
You aren't defining a start value.

Try:


For deleterate = 2 to ws.Range("O" & Rows.count).End(xlUp).Row
 
Upvote 0
MrKowz, thank you. I did't realize I needed a start value, works perfect now. Thanks again

Thanks for the feedback - glad we were able to get a working solution for you!
 
Upvote 0
You are welcome!

Google searches are great source of information for structures of these things and lots of examples.
There is a ton of good Excel information out there.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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