ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Code works within VBE but not from Excel (https://www.excelbanter.com/excel-programming/316878-code-works-within-vbe-but-not-excel.html)

SpaceCamel

Code works within VBE but not from Excel
 
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?

Dick Kusleika[_4_]

Code works within VBE but not from Excel
 
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.

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com

"SpaceCamel" wrote in message
...
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?




SpaceCamel

Code works within VBE but not from Excel
 
OK, That did it! Thanks.

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

===================
"Dick Kusleika" wrote:

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.

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com

"SpaceCamel" wrote in message
...
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?





JE McGimpsey

Code works within VBE but not from Excel
 
Because while you were in the VBE, sheet "List" was the active sheet?

In article ,
"SpaceCamel" wrote:

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



All times are GMT +1. The time now is 06:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com