+ Reply to Thread
Results 1 to 8 of 8

Help creating a macro button

  1. #1
    Registered User
    Join Date
    09-26-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2010
    Posts
    12

    Help creating a macro button

    Hi,

    Absolute beginner here.

    I would like a button which adds any number in column L to adjacent number in column I and then clear column L on each row.

    So as per attachment on Row 6 $3,500.00 + $4,500.00 = $8000.00 (new total for I6) L6 now empty cell and so on down the page.

    Note this test spreadsheet is a cut down version of a much larger sheet.

    eg: as per attached sheet

    Kind Regards,
    Glenn
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Help creating a macro button

    Hi,

    Try this.

    I have inserted some comments in the VBA that need your attention. To access these comments, right click on the worksheet name "MASTER" and select "View Code". Anything written in green is a comment, and is either something that requires your attention, or is informing you that you no longer need to change anything below a certain point in the code.

    I hope this helps you
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    09-26-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Help creating a macro button

    thank you that's exactly what I need. Can I copy this macro and button easily into a new spread sheet?

    Cheers!
    Glenn

  4. #4
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Help creating a macro button

    Yes you can, but you will need to make sure that row and column numbers match those consistent with the new sheet that you paste the macro into.

    Please don't forget to mark this thread as solved and click the * next to my post to say thank you

    Have a nice day!

  5. #5
    Registered User
    Join Date
    09-26-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Help creating a macro button

    One more small thing is below correct wording and placement to stop at row 200??

    Private Sub CommandButton1_Click()
    Dim i As Double
    Dim startRow As Double

    'This is what you want the button to say
    CommandButton1.Caption = "CALCULATE"

    'This is the first row in column L that you want the macro to look at
    startRow = 14
    endRow = 200
    'You do not need to change anything else after this point
    With ActiveSheet
    For i = startRow To .Cells(.Rows.Count, "L").End(xlUp).Row
    If IsNumeric(.Cells(i, "L").Value) Then
    'Sum column I and L
    .Cells(i, "I").Value = .Cells(i, "I").Value + .Cells(i, "L").Value
    'Reset column L
    .Cells(i, "L").Value = ""
    End If
    Next i
    End With
    End Sub

  6. #6
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Help creating a macro button

    Yep it sure is. The only thing you should need to change for that to take effect is the initial value of "endRow" (sorry, I just noticed that I forgot to put a comment on that line!). But what you have there looks fine to me.

    Please don't forget to mark this thread as solved and click the * next to my post to say thank you

  7. #7
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Help creating a macro button

    Hi,

    Please Login or Register  to view this content.
    [code]For i = startRow To .Cells(.Rows.Count, "D").End(xlUp).Row
    Maybe skip the empty cells via Specialcells.

    Ciao,
    Holger
    Last edited by HaHoBe; 08-15-2013 at 12:11 AM.
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  8. #8
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Help creating a macro button

    Are you being sarcastic? :P

    I suppose the alternative approach would have been
    Please Login or Register  to view this content.
    amongst many other possible methods of achieving the same outcome

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Creating a macro button with VBA
    By amotto11 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-15-2012, 12:50 PM
  2. VBA - Help creating a Macro for a button
    By JukeBoxHero in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 08-01-2012, 07:47 AM
  3. VBA - Help creating a Macro for a button
    By JukeBoxHero in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-11-2012, 07:53 AM
  4. Need Help creating a Macro with a Button
    By nn9955 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-30-2009, 03:24 PM
  5. Help Creating a Button through a Macro
    By Caligula in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-31-2007, 06:20 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1