![]() |
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 |
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 |
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 |
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 |
All times are GMT +1. The time now is 07:01 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com