+ Reply to Thread
Results 1 to 3 of 3

working with variables but wont add up

  1. #1
    Forum Contributor
    Join Date
    04-16-2016
    Location
    bognor
    MS-Off Ver
    Pro-Plus 2016
    Posts
    153

    working with variables but wont add up

    Hi all,

    I know I can use =(A1+A2) formula to add the contents of two values together.But I thought I would have a go at doing it with VBA.(not done a great deal with variables in vba)

    So I wrote this code(influenced a bit by VB.net) but it just doesn't work

    Sub addtwo()

    Dim a as Integer
    Dim b as Integer
    Dim c As integer

    Range("A1").Value = a
    Range("A2").Value = b
    Range("A3").Value = c

    c = a + b.

    So I place numbers in A1 and A2 on the spreadsheet but when I run the macro nothing happens.
    I also tried switching things round like this:

    a = Range("A1").Value

    But that didn't work either.

    I also gave the range it's complete address
    Sheet1.Range("A1") etc....but that didn't work either.

    I think my logic is near enough but I am obviously missing the point somewhere.
    Any help appreciated
    Barrow

  2. #2
    Forum Contributor kalbasiatka's Avatar
    Join Date
    02-27-2016
    Location
    Brest, Belarus
    MS-Off Ver
    2021
    Posts
    224

    Re: working with variables but wont add up

    Assign variable "a" the value of cell "A1"
    a = Range("A1").Value or a = Cells(1, 1)

    Please Login or Register  to view this content.
    if the variables are not needed immediately to work with cells
    Please Login or Register  to view this content.
    To do it for me and help me it is 2 different things!
    Sorry for my english, blame Google translator

  3. #3
    Forum Contributor
    Join Date
    04-16-2016
    Location
    bognor
    MS-Off Ver
    Pro-Plus 2016
    Posts
    153

    Re: working with variables but wont add up

    Many thanks for the reply and exactly what I wanted
    Barrow

+ 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] Multi choice formula for time sheet totals not working, wont sum hours
    By Dantro in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 05-21-2015, 09:58 AM
  2. [SOLVED] UDF as a Add-in wont add description of variables
    By jed38 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-24-2014, 03:45 PM
  3. Working 2007 excel add-in wont work with excell 2010 version. Please help.
    By kraft_mk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-25-2014, 08:53 PM
  4. worksheets variables from another sub not working
    By Leia in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-11-2011, 04:04 AM
  5. Working with Variables
    By Tim S in forum Excel General
    Replies: 4
    Last Post: 02-22-2011, 11:46 AM
  6. Working with time variables
    By brenaud in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-07-2011, 02:19 PM
  7. Excel 2007 : working with variables
    By envyjack001 in forum Excel General
    Replies: 0
    Last Post: 06-28-2009, 01:17 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