Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sub or function not defined.


I am trying to make a checkbox copy a cell to a different location, and
in the cells original location put the result of the moved cell + a
waste percentage, in this case being 10% "1.1"
The code looked okay to be except everytime i check to box to start the
process it says sub or function not defined... please help me out if i'm
doing something stupid.

Thanks!
Code below!


Code:
--------------------
Private Sub CheckBox1_Click()
If Cell(Z20 = "1") Then
Range("G20").Select
Selection.Copy
Range("AA20").Select
ActiveSheet.Paste
Range("G20").Select
ActiveCell.FormulaR1C1 = "=RC[20]*1.1"
Range("G20").Select
ElseIf Cell(Z20 = "2") Then
Range("C20").Select
Selection.Copy
Range("AA20").Select
ActiveSheet.Paste
Range("C20").Select
ActiveCell.FormulaR1C1 = "=RC[20]*1.1"
Range("C20").Select
End If
End Sub
--------------------


--
foxgguy2005
------------------------------------------------------------------------
foxgguy2005's Profile: http://www.excelforum.com/member.php...o&userid=23663
View this thread: http://www.excelforum.com/showthread...hreadid=376988

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sub or function not defined.


Change your code to:

Private Sub CheckBox1_Click()
If Range("Z20") = "1" Then
Range("G20").Select
Selection.Copy
Range("AA20").Select
ActiveSheet.Paste
Range("G20").Select
ActiveCell.FormulaR1C1 = "=RC[20]*1.1"
Range("G20").Select
ElseIf Range("Z20") = "2" Then
Range("C20").Select
Selection.Copy
Range("AA20").Select
ActiveSheet.Paste
Range("C20").Select
ActiveCell.FormulaR1C1 = "=RC[20]*1.1"
Range("C20").Select
End If
End Sub



Changes:
You had Cell(Z20="1")
which you probably meant
Range("Z20")=1

Mangesh


--
mangesh_yadav
------------------------------------------------------------------------
mangesh_yadav's Profile: http://www.excelforum.com/member.php...o&userid=10470
View this thread: http://www.excelforum.com/showthread...hreadid=376988

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Sub or function not defined.

The problem with your code is that the results in C20 and G20 will be 1.1x
the start value depending on 20. so If z20=1 and G20 was 10 then BOTH C20 and
G20 will show 11. If Z20=2 and C20 =5 then the code will result in BOTH C20
and G20 having 5.5

Take a look at this code...I think you'll find it a little clearer to
follow...

Private Sub CheckBox1_Click()

Select Case Range("Z20")

Case 1
Range("AA20").Value = Range("G20").Value
Range("G20").Formula = Range("G20").Value * 1.1
Range("G20").Select

Case 2
Range("AA20").Value = Range("C20").Value
Range("C20").Formula = Range("C20").Value * 1.1
Range("C20").Select
End Select
End Sub

You don't need to use AA20 at all, unless you need to keep the original. If
you don't then the code could be re-written....

Private Sub CheckBox1_Click()

Select Case Range("Z20")
Case 1
Range("G20").Formula = Range("G20").Value * 1.1
Range("G20").Select

Case 2
Range("C20").Formula = Range("C20").Value * 1.1
Range("C20").Select

End Select
End Sub


HTH
Patrick


"foxgguy2005" wrote:


I am trying to make a checkbox copy a cell to a different location, and
in the cells original location put the result of the moved cell + a
waste percentage, in this case being 10% "1.1"
The code looked okay to be except everytime i check to box to start the
process it says sub or function not defined... please help me out if i'm
doing something stupid.

Thanks!
Code below!


Code:
--------------------
Private Sub CheckBox1_Click()
If Cell(Z20 = "1") Then
Range("G20").Select
Selection.Copy
Range("AA20").Select
ActiveSheet.Paste
Range("G20").Select
ActiveCell.FormulaR1C1 = "=RC[20]*1.1"
Range("G20").Select
ElseIf Cell(Z20 = "2") Then
Range("C20").Select
Selection.Copy
Range("AA20").Select
ActiveSheet.Paste
Range("C20").Select
ActiveCell.FormulaR1C1 = "=RC[20]*1.1"
Range("C20").Select
End If
End Sub
--------------------


--
foxgguy2005
------------------------------------------------------------------------
foxgguy2005's Profile: http://www.excelforum.com/member.php...o&userid=23663
View this thread: http://www.excelforum.com/showthread...hreadid=376988


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sub or function not defined.


i love you pa

--
foxgguy200
-----------------------------------------------------------------------
foxgguy2005's Profile: http://www.excelforum.com/member.php...fo&userid=2366
View this thread: http://www.excelforum.com/showthread.php?threadid=37698

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
using a defined Name in a function cole Excel Worksheet Functions 2 July 31st 09 04:36 PM
Sub or function not defined wmdmurphy Excel Worksheet Functions 13 May 24th 09 05:50 PM
sumproduct function / VB user defined function aw Excel Discussion (Misc queries) 3 September 23rd 08 09:05 AM
Sub or Function not defined Patrick Simonds Excel Programming 3 May 22nd 04 07:17 PM
User-Defined Function pre-empting Built-in Function? How to undo???? MarWun Excel Programming 1 August 6th 03 09:31 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"