0
Sub TEST()
    If cells(i, "R").Value <> "UK" Then
        cells(i, "R").Interior.ColorIndex = 3
    End If
End Sub

If I run this program it throws application defined error \

I am new to Excel (beginner)

How to correct this error!!!

Thanks In advance

1
  • 3
    Add some explanation in your question on what you're trying to do with this code. Commented Sep 8, 2013 at 9:35

3 Answers 3

2

I think the issue is "R" that I know of the cells method takes 2 parameters one is rows the other is columns (in that order) but this is done by number not letter so if you change it to cell(1,18) then the code above works fine.

This link may also be useful to learn more, among other things it describes how you would normally select a range first as I believe your code above will assume the currently selected page, however you might want to run in on a button click from another page or as soon as the spreadsheet opens.

http://msdn.microsoft.com/en-us/library/office/ff196273.aspx

Sign up to request clarification or add additional context in comments.

Comments

2

The problem is that the variable i has not been assigned a value. VBA assumes that it is zero. Since i is used to determine the row of the cell, Excel throws an exception because there is no row 0!

Comments

1

First you have to define i variable

for example: Dim i as variant

1 Comment

If step 1 is declaring the variable i then step 0 is using Option Explicit to require variable declaration

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.