PC Review


Reply
Thread Tools Rate Thread

Command button code does not execute

 
 
twlove@ontuet.com
Guest
Posts: n/a
 
      3rd Jun 2007
I have a command button that when clicked is supposed to multiple the
value in R33 by 115% if cell N8 = Yes and by 130% if cell N8 = No.

What's wrong with my code?

******


Public Sub Calc_Freight()

Dim Assembly As String

Assembly = Range("N8")

Application.ScreenUpdating = False
Application.ActiveSheet.Range("R33").Select
Application.ScreenUpdating = True

Select Case ("Assembly")

Case "No"

For Each cell In Selection
cell.Value = cell.Value * 1.3
Next

Case "Yes"
For Each cell In Selection
cell.Value = cell.Value * 1.15
Next

End Select

End Sub

 
Reply With Quote
 
 
 
 
tissot.emmanuel
Guest
Posts: n/a
 
      3rd Jun 2007
Hi,

Try:

Select Case Assembly

instead of

Select Case ("Assembly")

Best regards from France,

Manu/


<(E-Mail Removed)> a écrit dans le message de news:
(E-Mail Removed)...
>I have a command button that when clicked is supposed to multiple the
> value in R33 by 115% if cell N8 = Yes and by 130% if cell N8 = No.
>
> What's wrong with my code?
>
> ******
>
>
> Public Sub Calc_Freight()
>
> Dim Assembly As String
>
> Assembly = Range("N8")
>
> Application.ScreenUpdating = False
> Application.ActiveSheet.Range("R33").Select
> Application.ScreenUpdating = True
>
> Select Case ("Assembly")
>
> Case "No"
>
> For Each cell In Selection
> cell.Value = cell.Value * 1.3
> Next
>
> Case "Yes"
> For Each cell In Selection
> cell.Value = cell.Value * 1.15
> Next
>
> End Select
>
> End Sub
>



 
Reply With Quote
 
=?Utf-8?B?Um9uIENvZGVycmU=?=
Guest
Posts: n/a
 
      3rd Jun 2007
You have some conflicting code....
On the one hand you seem to want to apply a factor to each cell in the
current selection...
But, within the code you select cell N33 (one cell)...then loop through all
ONE of them. (?)

If you really want to use the current selection,
try something like this:

'------------start of code---------------
Public Sub Calc_Freight()

Dim Assembly As String
Dim cCell As Range
Dim Factor

On Error GoTo errTrap

Assembly = Range("N8").Value

Select Case Assembly
Case "No"
Factor = 1.3
Case "Yes"
Factor = 1.15
Case Else
MsgBox "Neither Yes nor No!"
End Select

For Each cCell In Selection.Cells
cCell.Formula = cCell.Value * Factor
Next cCell

errTrap:
If Err.Number <> 0 Then
MsgBox _
Title:="Problems Encountered", _
Prompt:="Could not execute Calc_Freight" & vbCr & vbCr _
& "Error Number: " & Err.Number & ": " & Err.Description & " was
encountered", _
Buttons:=vbCritical + vbOKOnly
End If
End Sub
'------------end of code---------------


OTHERWISE......
If you only want to set the new value of cell N33..
Perhaps this:

'------------start of code---------------
Public Sub Calc_FreightN33()

Dim Assembly As String
Dim cCell As Range
Dim Factor

On Error GoTo errTrap

Assembly = Range("N8").Value

Select Case Assembly
Case "No"
Factor = 1.3
Case "Yes"
Factor = 1.15
Case Else
MsgBox "Neither Yes nor No!"
End Select

Set cCell = Range("N33")
cCell.Formula = cCell.Value * Factor

errTrap:
If Err.Number <> 0 Then
MsgBox _
Title:="Problems Encountered", _
Prompt:="Could not execute Calc_Freight" & vbCr & vbCr _
& "Error Number: " & Err.Number & ": " & Err.Description & " was
encountered", _
Buttons:=vbCritical + vbOKOnly
End If

End Sub
'------------end of code---------------


Is that something you can work with?
***********
Regards,
Ron

XL2002, WinXP


"(E-Mail Removed)" wrote:

> I have a command button that when clicked is supposed to multiple the
> value in R33 by 115% if cell N8 = Yes and by 130% if cell N8 = No.
>
> What's wrong with my code?
>
> ******
>
>
> Public Sub Calc_Freight()
>
> Dim Assembly As String
>
> Assembly = Range("N8")
>
> Application.ScreenUpdating = False
> Application.ActiveSheet.Range("R33").Select
> Application.ScreenUpdating = True
>
> Select Case ("Assembly")
>
> Case "No"
>
> For Each cell In Selection
> cell.Value = cell.Value * 1.3
> Next
>
> Case "Yes"
> For Each cell In Selection
> cell.Value = cell.Value * 1.15
> Next
>
> End Select
>
> End Sub
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Command Button to execute a Function AJOLSON Microsoft Access Form Coding 1 16th Dec 2008 04:51 PM
Macro won't execute from a Command Button =?Utf-8?B?RGljayBTY2hlaWJl?= Microsoft Excel Programming 5 19th Aug 2005 01:39 AM
i am trying to Execute some command Bar Button but doesn't work =?Utf-8?B?ZG9ybGluZw==?= Microsoft Outlook Program Addins 3 27th Jun 2005 08:40 AM
How do I execute command from button or hyperlink? rerhart Microsoft Excel Misc 1 18th Feb 2005 09:41 PM
Command button - won't execute twice in sequence L Mehl Microsoft Excel Programming 6 15th Oct 2004 07:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:45 PM.