+ Reply to Thread
Results 1 to 7 of 7

Question about using VBA in Excel to change the value in a looked up cell

  1. #1
    Registered User
    Join Date
    12-30-2020
    Location
    Belgium
    MS-Off Ver
    MS Office 365
    Posts
    7

    Question Question about using VBA in Excel to change the value in a looked up cell

    Hello,

    I'm trying to create a macro button in VBA, which edits a certain cell (adds +1 to its value).

    The problem is, the correct cell should be looked up in a table, (I'm using a VLOOKUP function), like this one: VLOOKUP(A38;$A$50:$Q$59;6). The contents of A38 is changing all the time.

    Is there a way to code this in VBA? I tried using Worksheets.Range and Worksheets.Cells but I'm getting nowhere...



    Thanks alot!!

  2. #2
    Forum Contributor
    Join Date
    05-09-2021
    Location
    Sweden
    MS-Off Ver
    Office 365
    Posts
    148

    Re: Question about using VBA in Excel to change the value in a looked up cell

    Hello ExReey,

    Not sure I understand your question.

    With the formula you have above the result of the formula should update whenever the A38 value is updated, this is expected.

    Do you want to update A38 with +1 when pressing the button?

    Adding +1 to a cell is simple, just need to understand your question better

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Question about using VBA in Excel to change the value in a looked up cell

    An example of your workbook would have been useful.

    Maybe, assuming the vlookup is in A1

    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Registered User
    Join Date
    12-30-2020
    Location
    Belgium
    MS-Off Ver
    MS Office 365
    Posts
    7

    Re: Question about using VBA in Excel to change the value in a looked up cell

    Quote Originally Posted by MrChulo View Post
    Hello ExReey,

    Not sure I understand your question.

    With the formula you have above the result of the formula should update whenever the A38 value is updated, this is expected.

    Do you want to update A38 with +1 when pressing the button?

    Adding +1 to a cell is simple, just need to understand your question better
    Quote Originally Posted by Richard Buttrey View Post
    An example of your workbook would have been useful.

    Maybe, assuming the vlookup is in A1

    Please Login or Register  to view this content.
    Thanks for the replies!

    I'm creating an interactive combat tracker for a tabletop RPG.
    One of the parts is a table with stats for 10 opponents (stats include strength, willpower, and Wounds (=hitpoints)).
    When entering combat, players can choose which opponent they want to fight: the selected opponent is in cell A38.
    With a random number generator, and after some calculations are done, I get the total damage done to this selected opponent.

    So now I want to substract the damage done from the hitpoints of the correct enemy in the table (the enemy currently selected in cell A38).

    I want something like Range(*the value in A38 looked up in OpponentTable*).Value = Range().Value - [the damage done].

    Here is an image of OpponentTable:

    dLCIarN.jpg


    Does that make things a bit more clear?
    Last edited by ExReey; 05-16-2021 at 04:49 AM.

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Question about using VBA in Excel to change the value in a looked up cell

    I mentioned uploading your workbook. Pictures are rarely much use. See the standard response below and note the requirement to shoe a before and after.

    Please upload a workbook or a representative cut down copy, anonymised if necessary. It is always easier to advise if we can see your request in its context.

    Show a before and after situation with manually calculated results, explaining which information is data and which is results, and if it's not blindingly obvious how you have arrived at your results some explanatory notes as well.

    To upload a file click the Go Advanced button at the foot of your post, look underneath the post area for the Manage Attachments section and take it from there.

  6. #6
    Registered User
    Join Date
    12-30-2020
    Location
    Belgium
    MS-Off Ver
    MS Office 365
    Posts
    7

    Re: Question about using VBA in Excel to change the value in a looked up cell

    Thanks for the info.


    I added workbook to this post (stripped of all unnecessary components).

    1) You choose which opponent you want to fight, using the drop down in cell E23. This picks an opponent from the table A50:Q59.
    2) You choose 'ranged' or 'melee' combat in cell C21 (this changes the damage calculations).
    3) You press the D100 button, which generates a random number in C24 and F24. Using these numbers, I calculate the damage done to the chosen opponent and write it in cell F26.
    ---
    4) When I press the "Update W" button, this damage number (cell F26) should be substracted from the Wounds number (in red text) of the chosen opponent in the table; the column number of this Wounds cell is 8, but the row number is depending on the chosen opponent in cell E23.
    And that's exactly my problem
    Attached Files Attached Files
    Last edited by ExReey; 05-16-2021 at 05:24 AM.

  7. #7
    Forum Contributor
    Join Date
    05-09-2021
    Location
    Sweden
    MS-Off Ver
    Office 365
    Posts
    148

    Re: Question about using VBA in Excel to change the value in a looked up cell

    Hello ExReey,

    Now it is very clear

    Try this:
    Please Login or Register  to view this content.

+ 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. Connection refresh of source data and cell values saved and looked up
    By VBANoob_Mazura in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-23-2017, 05:42 PM
  2. [SOLVED] Help with IF function where a number of possible criteria are looked up in a cell
    By Charlie12345 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-13-2013, 07:47 AM
  3. VLOOKUP - copy over the color of the looked up cell?
    By Jeff_Johnson in forum Excel General
    Replies: 1
    Last Post: 03-05-2010, 01:25 PM
  4. Retrieve adajcent value from looked up cell
    By Chutney in forum Excel General
    Replies: 5
    Last Post: 09-04-2009, 12:33 PM
  5. offset a looked up cell
    By tiggz13 in forum Excel General
    Replies: 2
    Last Post: 06-24-2005, 11:05 AM
  6. offset a looked up cell
    By Buffett in forum Excel General
    Replies: 1
    Last Post: 03-29-2005, 03:06 PM
  7. [SOLVED] formula to return the value of a cell based on a looked up true reference
    By sarah in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-02-2005, 05: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