+ Reply to Thread
Results 1 to 4 of 4

Update cell number

  1. #1
    Registered User
    Join Date
    01-26-2005
    Posts
    5

    Update cell number

    Hi,
    I am a VBA beginner, how do i add a certain number to cell A1 from another cell? E.g. I want to add the number in cell E3 to cell A1, so the cell A1 gets updated. Heres a sample code i cant quite work:


    Sub Count()
    mycount = Range("a1") + 1
    Range("a1") = mycount
    End Sub

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Rav295,

    Here is how it is done. I am assuming both cells are on the same worksheet.

    'E3 = 15
    'A1 = 10

    MyCount = Range("E3").Value
    Range("A1").Value = Range("A1").Value + MyCount

    Now A1 = 25

    Easy once you know how,
    Leith Ross

  3. #3
    Registered User
    Join Date
    01-26-2005
    Posts
    5

    Different sheets

    Hi,
    Sorry i forgot to say, the cells are on different sheets. How do i go about that?

    Thanks

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Rav295,

    Here is how it is done when the cells are on different sheets. Prefix the range with the worksheet name.

    Assumptions
    'Worksheets("Sheet1").Range("E3").Value = 15
    'Worksheets("Sheet2").Range("A1").Value = 10

    Code
    MyCount = Worksheets("Sheet1").Range("E3").Value
    With Worksheets("Sheet2").Range("A1")
    .Value = .Value + MyCount
    End With

    Now Worksheets("Sheet2").Range("A1").Value = 25

    If you have any other question, just ask.

    Thanks,
    Leith Ross

+ 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