PC Review


Reply
Thread Tools Rate Thread

Change syntax

 
 
Ben in CA
Guest
Posts: n/a
 
      9th Dec 2008
Hi,

I'd like a macro that does the following logic when I press a command button
- how do I format this "code" for Excel's Visual Basic?

onclick {
if cell W6 of this worksheet is not empty or zero, copy it to field W6 on
worksheet "Sales" - unless that field is already full, then prompt to replace
or leave existing value.
}

Also, how do I clear a particular field in a different worksheet using a
macro command button?

Any responses appreciated!


 
Reply With Quote
 
 
 
 
Per Jessen
Guest
Posts: n/a
 
      9th Dec 2008

Hi

Insert two buttons from the "Command Toolbox" menu, then rightclick on one
of them. Click View code, and insert the code below to the codesheet which
appears. Close the code sheet and exit design mode.

Private Sub CommandButton1_Click()
If Range("W6").Value <> "" And Range("W6").Value <> 0 Then
If Sheets("Sales").Range("W6").Value <> "" Then
answer = MsgBox("Do you want to replace existing value?", vbYesNo)
If answer = vbYes Then Sheets("Sales").Range("W6") =
Me.Range("W6").Value
Else
Sheets("Sales").Range("W6") = Me.Range("W6").Value
End If
End If
End Sub

Private Sub CommandButton2_Click()
Sheets("Sales").Range("A1").ClearContents
End Sub

Hopes it helps

---
Per
"Ben in CA" <(E-Mail Removed)> skrev i meddelelsen
news:37F6850D-8484-4258-8D5B-(E-Mail Removed)...
> Hi,
>
> I'd like a macro that does the following logic when I press a command
> button
> - how do I format this "code" for Excel's Visual Basic?
>
> onclick {
> if cell W6 of this worksheet is not empty or zero, copy it to field W6 on
> worksheet "Sales" - unless that field is already full, then prompt to
> replace
> or leave existing value.
> }
>
> Also, how do I clear a particular field in a different worksheet using a
> macro command button?
>
> Any responses appreciated!
>
>


 
Reply With Quote
 
Ben in CA
Guest
Posts: n/a
 
      9th Dec 2008
Hi Per,

Incredible - thanks so much!

Thanks for the super quick and super useful reply!

Ben

"Per Jessen" wrote:

> Hi
>
> Insert two buttons from the "Command Toolbox" menu, then rightclick on one
> of them. Click View code, and insert the code below to the codesheet which
> appears. Close the code sheet and exit design mode.
>
> Private Sub CommandButton1_Click()
> If Range("W6").Value <> "" And Range("W6").Value <> 0 Then
> If Sheets("Sales").Range("W6").Value <> "" Then
> answer = MsgBox("Do you want to replace existing value?", vbYesNo)
> If answer = vbYes Then Sheets("Sales").Range("W6") =
> Me.Range("W6").Value
> Else
> Sheets("Sales").Range("W6") = Me.Range("W6").Value
> End If
> End If
> End Sub
>
> Private Sub CommandButton2_Click()
> Sheets("Sales").Range("A1").ClearContents
> End Sub
>
> Hopes it helps
>
> ---
> Per
> "Ben in CA" <(E-Mail Removed)> skrev i meddelelsen
> news:37F6850D-8484-4258-8D5B-(E-Mail Removed)...
> > Hi,
> >
> > I'd like a macro that does the following logic when I press a command
> > button
> > - how do I format this "code" for Excel's Visual Basic?
> >
> > onclick {
> > if cell W6 of this worksheet is not empty or zero, copy it to field W6 on
> > worksheet "Sales" - unless that field is already full, then prompt to
> > replace
> > or leave existing value.
> > }
> >
> > Also, how do I clear a particular field in a different worksheet using a
> > macro command button?
> >
> > Any responses appreciated!
> >
> >

>
>

 
Reply With Quote
 
Per Jessen
Guest
Posts: n/a
 
      10th Dec 2008
Hi Ben

Thanks for your reply. I'm glad to help.

Regards,
Per

"Ben in CA" <(E-Mail Removed)> skrev i meddelelsen
news:43652861-B389-487C-B4F7-(E-Mail Removed)...
> Hi Per,
>
> Incredible - thanks so much!
>
> Thanks for the super quick and super useful reply!
>
> Ben
>


 
Reply With Quote
 
Ben in CA
Guest
Posts: n/a
 
      11th Dec 2008
Hi Per,

Do you know how I would modify this so it could be done from a form button
instead of a command button?

(It's really useful already, but now I'm thinking it should have been a form
button.)

Also, is there any way that it could automatically replace (not ask) if the
value of C33 is 0 (zero)?

Private Sub CommandButton1_Click()

If Range("W6").Value <> "" And Range("W6").Value <> 0 Then
If Sheets("Quick Calculator").Range("C33").Value <> "" Then
answer = MsgBox("Do you want to replace existing value for Trade
1?", vbYesNo)
If answer = vbYes Then Sheets("Quick Calculator").Range("C33") =
Me.Range("W6").Value
Else
Sheets("Quick Calculator").Range("C33") = Me.Range("W6").Value
End If
End If

End Sub


Thanks Per! - you've been a great help!

(please take no offense - in case you aren't notified of replies, I'll
re-post this as a new topic.)

"Per Jessen" wrote:

> Hi Ben
>
> Thanks for your reply. I'm glad to help.
>
> Regards,
> Per
>
> "Ben in CA" <(E-Mail Removed)> skrev i meddelelsen
> news:43652861-B389-487C-B4F7-(E-Mail Removed)...
> > Hi Per,
> >
> > Incredible - thanks so much!
> >
> > Thanks for the super quick and super useful reply!
> >
> > Ben
> >

>
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      11th Dec 2008
Check your later post.

Ben in CA wrote:
>
> Hi Per,
>
> Do you know how I would modify this so it could be done from a form button
> instead of a command button?
>
> (It's really useful already, but now I'm thinking it should have been a form
> button.)
>
> Also, is there any way that it could automatically replace (not ask) if the
> value of C33 is 0 (zero)?
>
> Private Sub CommandButton1_Click()
>
> If Range("W6").Value <> "" And Range("W6").Value <> 0 Then
> If Sheets("Quick Calculator").Range("C33").Value <> "" Then
> answer = MsgBox("Do you want to replace existing value for Trade
> 1?", vbYesNo)
> If answer = vbYes Then Sheets("Quick Calculator").Range("C33") =
> Me.Range("W6").Value
> Else
> Sheets("Quick Calculator").Range("C33") = Me.Range("W6").Value
> End If
> End If
>
> End Sub
>
> Thanks Per! - you've been a great help!
>
> (please take no offense - in case you aren't notified of replies, I'll
> re-post this as a new topic.)
>
> "Per Jessen" wrote:
>
> > Hi Ben
> >
> > Thanks for your reply. I'm glad to help.
> >
> > Regards,
> > Per
> >
> > "Ben in CA" <(E-Mail Removed)> skrev i meddelelsen
> > news:43652861-B389-487C-B4F7-(E-Mail Removed)...
> > > Hi Per,
> > >
> > > Incredible - thanks so much!
> > >
> > > Thanks for the super quick and super useful reply!
> > >
> > > Ben
> > >

> >
> >


--

Dave Peterson
 
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
Color Change Syntax Minitman Microsoft Excel Programming 2 21st May 2008 08:47 PM
Syntax-Change? Peter Ostermann Microsoft Excel Programming 4 27th Jan 2007 04:52 PM
SQL syntax to change a primary key? Gary Kahrau Microsoft Access Queries 1 23rd Dec 2004 05:29 AM
Re: How do I change Syntax in Excel? Paul B Microsoft Excel Worksheet Functions 0 18th Sep 2003 08:35 PM
Change Marco into Code ? Need Syntax, Please Dave Elliott Microsoft Access Forms 2 28th Aug 2003 02:27 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:04 AM.