0

I am new to VBA and trying to solve a problem in VBA Excel. I am using "Option Explicit". Every time I run code in VBA a compile error appears. It says "variable not defined". How a variable is defined in VBA?

enter image description here

1
  • You are getting that error because your variable is not declared and you have used Option Explicit at the top which forces you to declare your variables as a specific data type. You may want to read up about it in To ‘Err’ is Human. See Point #2. Also when working with Excel rows, it is better to declare them as Long rather than Integer else you may get Overflow error. Commented Jun 29, 2021 at 8:02

1 Answer 1

0

This is very basic ...:

Dim i As Long

So, you need to study a primer "Beginning with VBA" or similar.

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

1 Comment

It is advisable to use Long rather than Integer when you are working with rows in Excel. Dim i As Long

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.