+ Reply to Thread
Results 1 to 7 of 7

Macro Solving One Line At A Time

  1. #1
    Registered User
    Join Date
    11-21-2022
    Location
    United States
    MS-Off Ver
    2022
    Posts
    4

    Macro Solving One Line At A Time

    I have the following macro, that I need to add a certain value "R9" to a list of cells "D14:D21"

    The problem is the cell "R9" is a variable and decreases after every occurrence, because increasing the value of "D14", decreases "R9".

    How do I get excel to add the value of "R9" to all the cells before "R9" decreases?

    I have also attached the excel sheet with the cells and macro.


    Sub BonusLap()
    '
    ' BonusLap Macro
    '
    ' Keyboard Shortcut: Ctrl+Shift+L


    Range("D14").Value = Range("D14").Value + Range("R9").Value
    Range("D15").Value = Range("D15").Value + Range("R9").Value
    Range("D16").Value = Range("D16").Value + Range("R9").Value
    Range("D17").Value = Range("D17").Value + Range("R9").Value
    Range("D18").Value = Range("D18").Value + Range("R9").Value
    Range("D19").Value = Range("D19").Value + Range("R9").Value
    Range("D20").Value = Range("D20").Value + Range("R9").Value
    Range("D21").Value = Range("D21").Value + Range("R9").Value

    '
    End Sub



    Thanks,

    Jason
    Attached Files Attached Files
    Last edited by kunjason; 11-21-2022 at 03:48 PM.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: Macro Solving One Line At A Time

    Maybe:

    Please Login or Register  to view this content.
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    11-21-2022
    Location
    United States
    MS-Off Ver
    2022
    Posts
    4

    Re: Macro Solving One Line At A Time

    Almost,

    Just had to adjust the range to "R9" and it worked.

    Thank you very much.

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: Macro Solving One Line At A Time

    You're welcome
    Last edited by protonLeah; 11-22-2022 at 03:47 PM.

  5. #5
    Registered User
    Join Date
    11-21-2022
    Location
    United States
    MS-Off Ver
    2022
    Posts
    4

    Re: Macro Solving One Line At A Time

    One more issue I am running into that is befuddling me.

    Cell D6 controls which cells D14:D21 are populated. I tried creating an if then saying:

    If ("D6") = "90" Then
    Range("R9").Copy
    Range("D14:D21").PasteSpecial _
    Paste:=xlPasteValues, _
    Operation:=xlAdd, _
    SkipBlanks:=False, _
    Transpose:=False
    End If


    But nothing happens...
    I've tried several other variations but I either get a syntax error or a block if error.

  6. #6
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: Macro Solving One Line At A Time

    There is nothing in D6; but the data in D7 is numeric (90). Your IF function is testing for string/text data (in double quotes).
    The two character string, "90", is not the same as 90. Also, note that you left out the key word "RANGE". So:
    If Range("D7").Value = 90 Then ...

  7. #7
    Registered User
    Join Date
    11-21-2022
    Location
    United States
    MS-Off Ver
    2022
    Posts
    4

    Re: Macro Solving One Line At A Time

    Once again, spot on.

    Thanks!

+ 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] I'm getting Run-time error ‘13’: type mismatch and unsure about solving.
    By sdingman in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 03-10-2020, 03:34 AM
  2. Replies: 3
    Last Post: 11-20-2018, 05:50 AM
  3. Replies: 9
    Last Post: 07-17-2014, 11:48 AM
  4. [SOLVED] Solving a time problem with conditional formatting
    By smig123 in forum Excel General
    Replies: 4
    Last Post: 02-03-2014, 10:59 AM
  5. Replies: 3
    Last Post: 06-10-2012, 11:02 AM
  6. Replies: 3
    Last Post: 01-12-2012, 02:24 PM
  7. Time Line Macro
    By E3iron in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-29-2009, 03:39 AM

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