ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Excel VBA Formula Help (https://www.excelbanter.com/excel-worksheet-functions/445592-excel-vba-formula-help.html)

Aaron

Excel VBA Formula Help
 
Hi Experts,

With Range("d10,d11,k10,n10,p10,t11,e12,v10")
If .NumberFormat = "0" Or .NumberFormat = "General" Then Exit Sub
.NumberFormat = "0.0"
Else
.NumberFormat = .NumberFormat & "0"
.NumberFormat = Replace(.NumberFormat, "0000", "000 0")
End If
End With

This is part of a button driven macro.

The problem is the exit sub part is causing the rest of the macro to not be run (not shown)

I have tried to place another macro call after "Then" but I cant get it to work.

It just moans about the ".NumberFormat = "0.0"" part.

I just need it to protect the worksheet if it is going to exit sub because at the end of this macros code I protect the sheet. When it exits, It doesnt ever get to run the code part that protects the sheet at the end.

TIA,

Aaron.

Don Guillett[_2_]

Excel VBA Formula Help
 
On Sunday, March 25, 2012 4:59:46 PM UTC-5, Aaron wrote:
Hi Experts,

With Range("d10,d11,k10,n10,p10,t11,e12,v10")
If .NumberFormat = "0" Or .NumberFormat = "General" Then Exit Sub
.NumberFormat = "0.0"
Else
.NumberFormat = .NumberFormat & "0"
.NumberFormat = Replace(.NumberFormat, "0000", "000 0")
End If
End With

This is part of a button driven macro.

The problem is the exit sub part is causing the rest of the macro to not be run (not shown)

I have tried to place another macro call after "Then" but I cant get it to work.

It just moans about the ".NumberFormat = "0.0"" part.

I just need it to protect the worksheet if it is going to exit sub because at the end of this macros code I protect the sheet. When it exits, It doesnt ever get to run the code part that protects the sheet at the end.

TIA,

Aaron.


You have




On Sunday, March 25, 2012 4:59:46 PM UTC-5, Aaron wrote:
Hi Experts,

With Range("d10,d11,k10,n10,p10,t11,e12,v10")
If .NumberFormat = "0" Or .NumberFormat = "General" Then Exit Sub
.NumberFormat = "0.0"
Else
.NumberFormat = .NumberFormat & "0"
.NumberFormat = Replace(.NumberFormat, "0000", "000 0")
End If
End With

This is part of a button driven macro.

The problem is the exit sub part is causing the rest of the macro to not be run (not shown)

I have tried to place another macro call after "Then" but I cant get it to work.

It just moans about the ".NumberFormat = "0.0"" part.

I just need it to protect the worksheet if it is going to exit sub because at the end of this macros code I protect the sheet. When it exits, It doesnt ever get to run the code part that protects the sheet at the end.

TIA,

Aaron.




On Sunday, March 25, 2012 4:59:46 PM UTC-5, Aaron wrote:
Hi Experts,

With Range("d10,d11,k10,n10,p10,t11,e12,v10")
If .NumberFormat = "0" Or .NumberFormat = "General" Then Exit Sub
.NumberFormat = "0.0"
Else
.NumberFormat = .NumberFormat & "0"
.NumberFormat = Replace(.NumberFormat, "0000", "000 0")
End If
End With

This is part of a button driven macro.

The problem is the exit sub part is causing the rest of the macro to not be run (not shown)

I have tried to place another macro call after "Then" but I cant get it to work.

It just moans about the ".NumberFormat = "0.0"" part.

I just need it to protect the worksheet if it is going to exit sub because at the end of this macros code I protect the sheet. When it exits, It doesnt ever get to run the code part that protects the sheet at the end.

TIA,

Aaron.




On Sunday, March 25, 2012 4:59:46 PM UTC-5, Aaron wrote:
Hi Experts,

With Range("d10,d11,k10,n10,p10,t11,e12,v10")
If .NumberFormat = "0" Or .NumberFormat = "General" Then Exit Sub
.NumberFormat = "0.0"
Else
.NumberFormat = .NumberFormat & "0"
.NumberFormat = Replace(.NumberFormat, "0000", "000 0")
End If
End With

This is part of a button driven macro.

The problem is the exit sub part is causing the rest of the macro to not be run (not shown)

I have tried to place another macro call after "Then" but I cant get it to work.

It just moans about the ".NumberFormat = "0.0"" part.

I just need it to protect the worksheet if it is going to exit sub because at the end of this macros code I protect the sheet. When it exits, It doesnt ever get to run the code part that protects the sheet at the end.

TIA,

Aaron.




On Sunday, March 25, 2012 4:59:46 PM UTC-5, Aaron wrote:
Hi Experts,

With Range("d10,d11,k10,n10,p10,t11,e12,v10")
If .NumberFormat = "0" Or .NumberFormat = "General" Then Exit Sub
.NumberFormat = "0.0"
Else
.NumberFormat = .NumberFormat & "0"
.NumberFormat = Replace(.NumberFormat, "0000", "000 0")
End If
End With

This is part of a button driven macro.

The problem is the exit sub part is causing the rest of the macro to not be run (not shown)

I have tried to place another macro call after "Then" but I cant get it to work.

It just moans about the ".NumberFormat = "0.0"" part.

I just need it to protect the worksheet if it is going to exit sub because at the end of this macros code I protect the sheet. When it exits, It doesnt ever get to run the code part that protects the sheet at the end.

TIA,

Aaron.


You are asking excel to leave
If you want the rest you need an additional IF
Tell us what you want?

With Range("d10,d11,k10,n10,p10,€‹t11,e12,v10")
If .NumberFormat = "0" Or .NumberFormat = "General" Then Exit Sub



.NumberFormat = "0.0"
Else
.NumberFormat = .NumberFormat & "0"
.NumberFormat = Replace(.NumberFormat, "0000", "000 0")
End If
End With

Aaron

Excel VBA Formula Help
 
On Monday, March 26, 2012 10:59:46 AM UTC+13, Aaron wrote:
Hi Experts,

With Range("d10,d11,k10,n10,p10,t11,e12,v10")
If .NumberFormat = "0" Or .NumberFormat = "General" Then Exit Sub
.NumberFormat = "0.0"
Else
.NumberFormat = .NumberFormat & "0"
.NumberFormat = Replace(.NumberFormat, "0000", "000 0")
End If
End With

This is part of a button driven macro.

The problem is the exit sub part is causing the rest of the macro to not be run (not shown)

I have tried to place another macro call after "Then" but I cant get it to work.

It just moans about the ".NumberFormat = "0.0"" part.

I just need it to protect the worksheet if it is going to exit sub because at the end of this macros code I protect the sheet. When it exits, It doesnt ever get to run the code part that protects the sheet at the end.

TIA,

Aaron.


I solved this myself.

After a weekend break from it I saw the logic.

With Range("d10,d11,k10,n10,p10,€‹t11,e12,v10")
If .NumberFormat = "0" Or .NumberFormat = "General" Then sheets("Extended").Protect
If .NumberFormat = "0" Or .NumberFormat = "General" Then Exit Sub
.NumberFormat = "0.0"
Else
.NumberFormat = .NumberFormat & "0"
.NumberFormat = Replace(.NumberFormat, "0000", "000 0")
End If
End With

Thanks anyway.

Don Guillett[_2_]

Excel VBA Formula Help
 
On Sunday, March 25, 2012 4:59:46 PM UTC-5, Aaron wrote:
Hi Experts,

With Range("d10,d11,k10,n10,p10,t11,e12,v10")
If .NumberFormat = "0" Or .NumberFormat = "General" Then Exit Sub
.NumberFormat = "0.0"
Else
.NumberFormat = .NumberFormat & "0"
.NumberFormat = Replace(.NumberFormat, "0000", "000 0")
End If
End With

This is part of a button driven macro.

The problem is the exit sub part is causing the rest of the macro to not be run (not shown)

I have tried to place another macro call after "Then" but I cant get it to work.

It just moans about the ".NumberFormat = "0.0"" part.

I just need it to protect the worksheet if it is going to exit sub because at the end of this macros code I protect the sheet. When it exits, It doesnt ever get to run the code part that protects the sheet at the end.

TIA,

Aaron.


You still have and end if without an if

GS[_2_]

Excel VBA Formula Help
 
Aaron wrote :
On Monday, March 26, 2012 10:59:46 AM UTC+13, Aaron wrote:
Hi Experts,

With Range("d10,d11,k10,n10,p10,t11,e12,v10")
If .NumberFormat = "0" Or .NumberFormat = "General" Then Exit Sub
.NumberFormat = "0.0"
Else
.NumberFormat = .NumberFormat & "0"
.NumberFormat = Replace(.NumberFormat, "0000", "000 0")
End If
End With

This is part of a button driven macro.

The problem is the exit sub part is causing the rest of the macro to not be
run (not shown)

I have tried to place another macro call after "Then" but I cant get it to
work.

It just moans about the ".NumberFormat = "0.0"" part.

I just need it to protect the worksheet if it is going to exit sub because
at the end of this macros code I protect the sheet. When it exits, It doesnt
ever get to run the code part that protects the sheet at the end.

TIA,

Aaron.


I solved this myself.

After a weekend break from it I saw the logic.

With Range("d10,d11,k10,n10,p10,€‹t11,e12,v10")
If .NumberFormat = "0" Or .NumberFormat = "General" Then
sheets("Extended").Protect If .NumberFormat = "0" Or .NumberFormat =
"General" Then Exit Sub .NumberFormat = "0.0"
Else
.NumberFormat = .NumberFormat & "0"
.NumberFormat = Replace(.NumberFormat, "0000", "000 0")
End If
End With

Thanks anyway.


This doesn't make any sense (or logic)! Why all the redundancy? Why
test NumberFormat 2x? If you're trying to correct/revise a NumberFormat
then why not just assign the desired format?

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion




All times are GMT +1. The time now is 03:44 AM.

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