0

I have the following macro in VBA, and I am trying to get it to work, but I get an error: "Compile Error: Object Required"

Sub Macro6()


' Macro6 Macro


Dim counts As Integer

Set counts = 27

Do While counts < 28

SolverOK SetCell:=Sheets("Slag Case_forcedConvection").Cells(counts, 66), MaxMinVal:=3, ValueOf:=1, ByChange:=Sheets("Slag Case_forcedConvection").Cells(counts, 32)

SolverSolve userfinish:=True

   counts = counts + 1

End Sub
2
  • 2
    Set counts = 27 remove the set Commented Jun 24, 2016 at 20:44
  • When you get errors, be sure to tell us what line is indicated with the error Commented Jun 25, 2016 at 13:26

2 Answers 2

3

The correct syntax of a VBA Do While Loop is

Do While *Condition*

CODE

Loop

You are missing the 'Loop' at the bottom.

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

Comments

1

Integers/Longs do not need to be set they only need to be defined. Objects and Ranges require the set command.

As you are using an Integer you should remove Set from Set counts = 27.

If you still get the error, it is good practice to step though your code with F8 (or break/pause the code) to see exactly which line errors are occurring on.

http://www.vbtutor.net/ provides some good tutorials for starting out in case you wanted a solid introduction to VB coding. I hope this helps...

Comments

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.