While Loop in Excel VBA

5 pts.
Tags:
Excel 2003
VBA
Visual Basic for Applications
I have the basic loop and can not figure out what to write in the middle. I need to have row 9 column D populate a value from another sheet depending on the value in cell A9. Here is what I have so far:

 Private Sub Loop1() Dim myLoopCtr As Integer myLoopCtr = 0 While myLoopCtr <= 15 myLoopCtr = myLoopCtr + 1 Wend End Sub
 
ASKED: March 21, 2008  10:34 PM
UPDATED: April 18, 2013  2:20 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

Hello,

Why not use a Select Case statement instead?

Sub SetMyValue()

Select Case Range("A9").Value
Case "123"
Range("D9").Value = "something"
Case "456"
Range("E5").Value = "something else"
Case Else
End Select

End Sub

Selecting cells will result in very slow code.

HTH,
JP

Try this, changing the hello excel part of course, this should get you started:

Sub main()

Range("D9").Select
ActiveCell.FormulaR1C1 = "Hello Excel"
Range("D9").Select
Selection.Font.Bold = True
End Sub

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following