+ Reply to Thread
Results 1 to 3 of 3

Need help setting cell value as variable

  1. #1
    Registered User
    Join Date
    12-06-2014
    Location
    Pacific Northwest
    MS-Off Ver
    Excel 2010
    Posts
    17

    Need help setting cell value as variable

    Hello! I'm new to VBA and this forum, so this may be a simple question but I can't find an example online that works/makes sense to me.

    I have a workbook of data and statistics. I'm using these statistics to make a sort of Role Playing Game based around 'XP'. With that being said, the XP should never go down, only up. I'm trying to write a few lines into my 'update' macro that will essentially take their current XP, move it to a neighboring cell, do all of the updates, and compare the new XP to the old amount. If the old amount is higher, it's copied/pasted back.

    I have all of the code written for the macro, but I can't seem to figure out how to set the variables the right way (never really set variables) so that I can do that part.

    Can you help? Thanks in advance!!

  2. #2
    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: Need help setting cell value as variable

    Hi, OakMatt,

    use WorksheetFunction.Max when comparing the values to write them back. Range("C3") is the old one, Range("B3") is the cell that holds the new and should hold the updated one:
    Please Login or Register  to view this content.
    But instead of writing to a different cell I would store it in a variable and compare it from there leavoing the SS empty of helpers.

    Ciao,
    Holger
    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

  3. #3
    Registered User
    Join Date
    12-06-2014
    Location
    Pacific Northwest
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Need help setting cell value as variable

    Great! Thank you very much.

+ 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] Small Issue with Type Mismatch and Invalid Qualifier when setting variable value from cell
    By TomToms in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-10-2014, 08:03 AM
  2. [SOLVED] Setting a Public Variable = the Active Cell
    By slm10 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-21-2014, 07:56 AM
  3. Setting cell reference as variable.
    By qcity in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 06-21-2011, 02:57 AM
  4. Setting integer variable to cell contents
    By ChemistB in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-06-2008, 03:53 PM
  5. Setting a variable cell address
    By Hugh Jago in forum Excel General
    Replies: 3
    Last Post: 01-05-2005, 12:06 PM

Tags for this Thread

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