Code works within VBE but not from Excel

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have code that populates a list of cells then applies formating depending
on the content. Like:

If APercent > 0 And APercent < 100 Then
Worksheets("List").Range(Cells(tcnt + 4, 4), Cells(tcnt + 4,
8)).Font.ColorIndex = 10
End If

The code works fine when run from within the VB Editor. But if I run it
from Excel (menu or button) the cells are populated but the cells are not
formated. I have tested that the formatting code is being run.

Any ideas of what is going on here?
 
SC

Just a guess, but it may be because you have unqualified Cells methods.
Depending on where your code is the Cells will be method of the ActiveSheet,
not Worksheets("List")

With Worksheets("List")
.Range(.Cells(tcnt+4,4),.Cells(tcnt+4,8).font etc..
End With

Note the period before Cells. I think if this was the problem, then you
would get an error, but it's all I could see.
 
OK, That did it! Thanks.

Now tell me why it worked from the VBE but didn't from from the App?

===================
 
Because while you were in the VBE, sheet "List" was the active sheet?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top