+ Reply to Thread
Results 1 to 17 of 17

Simple Cell Value +1 macro

  1. #1
    Registered User
    Join Date
    01-24-2010
    Location
    Vientiane, Laos
    MS-Off Ver
    Excel 2003
    Posts
    11

    Simple Cell Value +1 macro

    Hello,

    I'm trying to write a basic macro which will increase the value in a cell by 1 when I click on the button I've made. I've searched for hours on the Internet, including this site, and found several websites which give a formula needed but none of them work, I always get an "Object variable not set" error or something about sub-functions which I can't recreate so I can't give the full error message. Sorry.

    Based on what I've seen on the Internet, I currently have:

    Please Login or Register  to view this content.
    Where B18 is the cell which currently says 0 and I want to go up by one every time I click the button.

    In this macro, the B18 and the 1 are highlighted in red, presumably meaning they're the bits that are wrong. I get a "Basic runtime error: Object variable not set" error when I run it.

    Thanks in advance for any help.
    Last edited by Barns; 01-24-2010 at 06:31 AM.

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Simple Cell Value +1 macro

    hi Barns

    Your macro is OK ,can you please place your code between the code tags
    [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code]
    What type of button do you have?
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Registered User
    Join Date
    01-24-2010
    Location
    Vientiane, Laos
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Simple Cell Value +1 macro

    I wasn't sure what you meant by placing my code between the code tags, excuse my noobiness when it comes to programming. I've edited my post in the way I think you meant. Is that what you meant?

    It's a normal push button you get to through View>Toolbars>Form Controls. I assigned the macro I wrote to the button but I get the error message I quoted when I press it.

    Any ideas?

  4. #4
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Simple Cell Value +1 macro

    Hi Barns
    No! It works OK for me. Can you attach a small sample workbook?

  5. #5
    Registered User
    Join Date
    01-24-2010
    Location
    Vientiane, Laos
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Simple Cell Value +1 macro

    I've attached the actual spreadsheet I'm trying to add the button & macro on. None of the information on it would mean anything to anyone else so no worries.

    If you look on the January sheet in the January 2nd column you'll see the push button, labelled Button for the moment, in C18 and the 0 in cell B18.

    Thanks for your help.
    Attached Files Attached Files

  6. #6
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Simple Cell Value +1 macro

    Hey Banes

    This one is working now .
    To have a look
    Press the "Alt" key plus the "F11" key
    Attached Files Attached Files

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Simple Cell Value +1 macro

    I've added a macro to increment a specified cell by one. The macro is called using a Command Button from the Controls ToolBox. You can use the same macro & add a button to each tab.
    Attached Files Attached Files
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  8. #8
    Registered User
    Join Date
    01-24-2010
    Location
    Vientiane, Laos
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Simple Cell Value +1 macro

    With your one I get the error:

    A Scripting Framework error occurred while running the Basic script vnd.sun.star.script:Standard.Module1.WebsitePlus?
    language=Basic&location=document

    Message:The following Basic Script could not be found:
    library: 'Standard'
    module: 'Module1'
    method: 'WebsitePlus'
    location: 'document'

    So it basically seems as if the macro doesn't exist, no?

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Simple Cell Value +1 macro

    Quote Originally Posted by Barns View Post
    With your one I get the error:

    A Scripting Framework error occurred while running the Basic script vnd.sun.star.script:Standard.Module1.WebsitePlus?
    language=Basic&location=document

    Message:The following Basic Script could not be found:
    library: 'Standard'
    module: 'Module1'
    method: 'WebsitePlus'
    location: 'document'

    So it basically seems as if the macro doesn't exist, no?
    Whose code are you referring to,although both work?

    Are you using this in Excel?

  10. #10
    Registered User
    Join Date
    01-24-2010
    Location
    Vientiane, Laos
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Simple Cell Value +1 macro

    Both your macros all have 'Rem ' in front of all the commands. I thought Rem meant 'Reminder' and stopped the command being activated?

    I was referring to Pike's since my Internet dropped out so when I finally managed to post your post had been added without me knowing. I've tried yours too and nothing happens at all when I push the button. Also, on yours (RoyUK) whereabouts would I enter the cell number in the macro? I'm very new to macros so you'll have to bear with me.

    It's not Excel, it's OpenOffice, but I thought they were exactly the same? I think I've got an Office 2003 disc somewhere, I'll install that and try it on that. Sorry if I've made a faux-pas asking on an Excel forum when I'm using OpenOffice.

  11. #11
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Simple Cell Value +1 macro

    Unfortunately OpenOffice VBA is different to MS Excel's.

    In my code using the button you specify the cell within the brackets - in the example Cells(18,2) is B18

    Please Login or Register  to view this content.
    The main code takes the cell from the calling code & will increment B18
    Please Login or Register  to view this content.
    Not sure what changes you need for OpenOffice though

  12. #12
    Registered User
    Join Date
    01-24-2010
    Location
    Vientiane, Laos
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Simple Cell Value +1 macro

    Sorry to have wasted your time, it was an innocent mistake, I thought they were exactly the same. I'll install Excel and try it on that.

  13. #13
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Simple Cell Value +1 macro

    Using Google I found this site

    http://wiki.services.openoffice.org/...lls_and_Ranges

    As I've noticed before the code looks way more complicated, this adaption might work.

    Please Login or Register  to view this content.
    Try it and let me know

  14. #14
    Registered User
    Join Date
    01-24-2010
    Location
    Vientiane, Laos
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Simple Cell Value +1 macro

    Quote Originally Posted by royUK View Post
    Using Google I found this site

    http://wiki.services.openoffice.org/...lls_and_Ranges

    As I've noticed before the code looks way more complicated, this adaption might work.

    Please Login or Register  to view this content.
    Try it and let me know
    Whereabouts in that would I put the cell number B18 (the cell I want to go up by 1)? Would it be a (2, 18) for B and 18 after the getCellByPosition?

  15. #15
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Simple Cell Value +1 macro


  16. #16
    Registered User
    Join Date
    01-24-2010
    Location
    Vientiane, Laos
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Simple Cell Value +1 macro

    Quote Originally Posted by royUK View Post
    Using Google I found this site

    http://wiki.services.openoffice.org/...lls_and_Ranges

    As I've noticed before the code looks way more complicated, this adaption might work.

    Please Login or Register  to view this content.
    Try it and let me know
    You're a star Roy. That worked beautifully! Although, to get it to increase the value in B18 I had to change the values in brackets to 1, 17 which makes no sense whatsoever to my mind. Oh well, it works. Thanks so much for your help mate.

  17. #17
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Simple Cell Value +1 macro

    Looks like OO references aren't as intuitive as Excel's - Rows & Columns start at 1

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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