+ Reply to Thread
Results 1 to 4 of 4

code to add two cells together with relational cell names

  1. #1
    Registered User
    Join Date
    10-17-2005
    Posts
    27

    code to add two cells together with relational cell names

    That's probably a terrible thread title, but I'll explain here...

    I'm basically taking over the maintenance of a complex Excel spreadsheet with lots of VB code from a much more experienced programmer who is no longer with our company. This is sort of a side project and not what we do, so there aren't many people around to ask.

    So...here's the piece of code I'm working on - don't laugh. I did this to show you what I'm trying to do:

    Please Login or Register  to view this content.
    So, I'm basically telling it that when it creates the worksheet that I'm programming for, I want the forumula in the cell to be (if we are currently on row 24, for example) =B22 + B23

    So, very simple, right? I just don't know how to write this code to back up two and then one row, because the 22 and 23 could be different on different worksheets.

    Let me know if you need more info, and tia!
    Last edited by rylo; 08-14-2008 at 09:27 PM.

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Firstly can you please remember to wrap your code. I've done it for you this time, but you have a few posts on the programming forum so you should be aware of code wrapping.

    You code as it stands should work as you require depending on how the variable intCurrentRow is handled. Can you explain / show the code that initialises / updates this variable? Basically, if it is somehow aligned to your current cell, then it will always add the 2 rows immediately above (assuming this is possible...)

    rylo

  3. #3
    Registered User
    Join Date
    10-17-2005
    Posts
    27

    Rylo

    So sorry for not wrapping the code. I don't think I ever knew about it, but if I did I forgot. Thanks for the reminder.

    Here's the code where the guy set up the intCurrentRow. My code as it stands is getting an error, so something must be off:

    Please Login or Register  to view this content.
    Last edited by rylo; 08-14-2008 at 11:28 PM.

  4. #4
    Registered User
    Join Date
    10-17-2005
    Posts
    27
    Well - nevermind!!

    I tried it again and it worked! No idea what happened with the error the first time. Thanks for the help.

+ 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