Announcement

Collapse
No announcement yet.

Excel Macro Help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Excel Macro Help

    Hi Guys,

    Looking for some help from any excel gurus out there. What I need to do is create a macro then when for example i enter the number 10 in cell A5 it automatically takes the value 10 and divides it by 3.76 and puts the resultant value in the same cell. Not worked with excel since school so any help would be appreciated.

    Many Thanks

  • #2
    Pete,
    Is it a specific cell all the time or any cell in the worksheet?

    Goblin 500
    | Blade 130x | Blade 180cfx
    Spektrum DX8


    GWR Pilot 2011 & 2012

    Comment


    • #3
      Re: Excel Macro Help

      Originally posted by danch View Post
      Pete,
      Is it a specific cell all the time or any cell in the worksheet?
      Hi mate its a range of cells A5:A10 in a worksheet.

      Cheers

      Comment


      • #4
        Put this in the Workbook_SheetChange event in the VBA Editor :

        On Error GoTo Error_Out
        With Application
        .ScreenUpdating = False
        .EnableEvents = False
        End With

        If Not Intersect(Target, Target) Is Nothing Then
        Application.EnableEvents = False

        Target.Value = Target.Value / 3.76

        End If

        Continue_On:
        With Application
        .ScreenUpdating = True
        .EnableEvents = True
        End With
        Exit Sub

        Error_Out:
        MsgBox Err.Description
        Resume Continue_On

        Goblin 500
        | Blade 130x | Blade 180cfx
        Spektrum DX8


        GWR Pilot 2011 & 2012

        Comment


        • #5
          Sorry missed your reply, use this for those specific cells :

          On Error GoTo Error_Out

          With Application
          .ScreenUpdating = False
          .EnableEvents = False
          End With

          If Not Intersect(Target, Range("A5:A10")) Is Nothing Then
          Application.EnableEvents = False

          Target.Value = Target.Value / 3.76

          End If

          Continue_On:
          With Application
          .ScreenUpdating = True
          .EnableEvents = True
          End With
          Exit Sub

          Error_Out:
          MsgBox Err.Description
          Resume Continue_On

          Goblin 500
          | Blade 130x | Blade 180cfx
          Spektrum DX8


          GWR Pilot 2011 & 2012

          Comment


          • #6
            This will divide any cell in the A5:A10 range by 3.76 & will work on all the worksheets in the workbook

            Dan

            Goblin 500
            | Blade 130x | Blade 180cfx
            Spektrum DX8


            GWR Pilot 2011 & 2012

            Comment


            • #7
              Re: Excel Macro Help

              Originally posted by danch View Post
              This will divide any cell in the A5:A10 range by 3.76 & will work on all the worksheets in the workbook

              Dan
              Hi Mate,

              Thanks for the reply I have pasted the code into my worksheet which is one of several in the workbook however it does not compile it just says 'label not defined' on the first line of code.

              Cheers

              Comment


              • #8
                Excel Macro Help

                Does it really need to be a macro? I would use two separate tabs. Tab 1 has the original values in range A5:A15 and tab 2 has the same formatting but has formulas in the range referring to the original data. (ie: =sheet1!A5/3.75)
                Charles - Align 500EFL Pro - Blade 130x - Blade mCPx v2 - Spektrum DX6i & Phoenix Sim

                Comment


                • #9
                  If you Alt + F11 , then double click on the left 'This Workbook' you should then get 2 dropdown options at the top of the screen, drop the left one down to say 'Workbook' & then the right one to say SheetChange.

                  This should then give you :
                  Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)


                  End Sub
                  Paste my code in between the Private Sub & End Sub

                  Also
                  what version of excel are you using 2003/2007/2010 ?
                  Dan
                  Last edited by danch; 09-01-2013, 02:21 PM.

                  Goblin 500
                  | Blade 130x | Blade 180cfx
                  Spektrum DX8


                  GWR Pilot 2011 & 2012

                  Comment


                  • #10
                    Re: Excel Macro Help

                    Originally posted by danch View Post
                    If you Alt + F11 , then double click on the left 'This Workbook' you should then get 2 dropdown options at the top of the screen, drop the left one down to say 'Workbook' & then the right one to say SheetChange.

                    This should then give you :


                    Paste my code in between the Private Sub & End Sub

                    Also
                    what version of excel are you using 2003/2007/2010 ?
                    Dan
                    Hi Mate,

                    Tried that but the left drop down only gives me worksheet not workbook and I'm on excel 2003.

                    Cheers

                    Comment


                    • #11
                      Try this
                      Attached Files

                      Goblin 500
                      | Blade 130x | Blade 180cfx
                      Spektrum DX8


                      GWR Pilot 2011 & 2012

                      Comment


                      • #12
                        Originally posted by pjbrazendale View Post
                        Hi Mate,

                        Tried that but the left drop down only gives me worksheet not workbook and I'm on excel 2003.

                        Cheers
                        Ok, select 'Worksheet' & then 'Change'

                        & paste it in that Sub, will still work but just for the sheet you have selected.

                        Dan

                        Goblin 500
                        | Blade 130x | Blade 180cfx
                        Spektrum DX8


                        GWR Pilot 2011 & 2012

                        Comment

                        Working...
                        X