+ Reply to Thread
Results 1 to 13 of 13

Macro range of cells change

  1. #1
    Registered User
    Join Date
    10-14-2018
    Location
    Brampton, ontario
    MS-Off Ver
    2007
    Posts
    74

    Macro range of cells change

    Hi

    I have a macro that is not searching a cell range properly. If someone could kindly assist. Please see my Excel image.

    Example with expected result.

    The first part of the macro works fine it’s the last part that is not working correctly. As per my Excel image cell B30 has the number 7-15 in it. I need the macro to go to the cell below B31 and use that number (1 in this example) and search the following cell range: E1:E12 to find a 1 (cell E1). Once found place the 7-15 and increase the last digit by 1 (so it becomes 7-16) in the adjacent cell to the right (F1). Do the same with all cells: B30, F30 and J30 but only if they contain a 15 (1-15 or 7-15 etc.) as the last number. After this delete all contents in cell B30, C30, D30. There are are two examples in my Excel sheet.

    Thank-you in advance for your assistance.

    Please Login or Register  to view this content.
    EXCEL IMAGE.JPEG

  2. #2
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,028

    Re: Macro range of cells change

    Hi, CHRISTINEKENDALL93
    Can you upload your sample workbook, showing the 'before data' & the result you expected?
    That way we don't need to retype your data sample.

    To attach an Excel file:
    in the reply box, scroll down and press Go Advanced button and then scroll down and press Manage Attachments link. Follow the instructions to upload file.

    For the moment, I don't quite understand this part:

    Please Login or Register  to view this content.
    but you have no data in row 13 & 14, so actually what do you expect?

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

    Re: Macro range of cells change

    Also, Right(pair, 1) = 15 is trying to compare the last string character (i.e. "5") with the number 15. You need:
    Right(pair, 2)="15" to compare string characters.
    Ben Van Johnson

  4. #4
    Forum Expert
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,513

    Re: Macro range of cells change

    Any wrong in this makro
    Please Login or Register  to view this content.
    "Presh Star Who has help you *For Add Reputation!! And mark case as Solve"

  5. #5
    Registered User
    Join Date
    10-14-2018
    Location
    Brampton, ontario
    MS-Off Ver
    2007
    Posts
    74

    Re: Macro range of cells change

    Hi

    Thanks for your response. I will try the code and let you know..

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

    Re: Macro range of cells change

    Re:Right(pair.Value, 2) = 15 .....--->...Error
    Must be:
    either:
    Val(Right(pair.Value, 2)) = 15
    or
    Right(pair.Value, 2) = "15"

  7. #7
    Registered User
    Join Date
    10-14-2018
    Location
    Brampton, ontario
    MS-Off Ver
    2007
    Posts
    74

    Re: Macro range of cells change

    Hi

    The macro works but not the last part. As per my Excel image cell B30 has the number 7-15 in it. I need the macro to go to the cell below B31 and use that number (1 in this example) and search the following cell range: E1:E12 to find a 1 (cell E1). Once found place the 7-15 and increase the last digit by 1 (so it becomes 7-16) in the adjacent cell to the right (F1). Do the same with all cells: B30, F30 and J30 but only if they contain a 15 (1-15 or 7-15 etc.) as the last number. After this delete all contents in cell B30, C30, D30. There are are two examples in my Excel sheet.

    Thank-you again for your assistance.

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

    Re: Macro range of cells change

    Post a sample file including the current macro code you are working with.

  9. #9
    Registered User
    Join Date
    10-14-2018
    Location
    Brampton, ontario
    MS-Off Ver
    2007
    Posts
    74

    Re: Macro range of cells change

    Hi

    I have attached my Excel sheet with your changes but the macro is not working anymore.
    I have also included cells that were not in the original Excel image.
    Thanks so much for your help.
    Attached Files Attached Files

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

    Re: Macro range of cells change

    The code below will do as indicated in post #7; but, I don't understand what you are doing with the accumulator in the original code. Rows 13 & 14 don't match up with the descriptions.
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    10-14-2018
    Location
    Brampton, ontario
    MS-Off Ver
    2007
    Posts
    74

    Re: Macro range of cells change

    Hi protonLeah

    It works but a couple of issues: using my Excel sample sheet above when it finds the 7-15 (cell B30) it doesn’t use the cell below, cell B31 (1 in it) to search the cell range E1:E12 to find the number 1. The other issue is cell J30 also has a 1-15 in it. Right now both finds Cell B30 and J30 are placed in the same cell outside the range of E1:E12.

    Also, the contents of cell B30 and J30 are deleted after the move could we also delete the contents of cells C30 and D30. Also the contents of K30 and L30.

    Thanks again for your help.

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

    Re: Macro range of cells change

    I've modified the code to put repeated values from row 31 in the first empty column to the right of E in the matched row.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by protonLeah; 11-09-2018 at 12:56 AM.

  13. #13
    Registered User
    Join Date
    10-14-2018
    Location
    Brampton, ontario
    MS-Off Ver
    2007
    Posts
    74

    Re: Macro range of cells change

    Hi protonLeah

    It works, it works. Thank-you so much for your effort.
    Christine

+ 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] Change On_Open macro to a cell change in a range of cells
    By davidpierce in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-27-2015, 02:46 PM
  2. [SOLVED] Run a macro when a change occurs in a range of cells (two macros and two cell ranges)
    By zanguard80 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-03-2014, 07:11 AM
  3. [SOLVED] Macro to Clear contents in a range of cells when Date change.
    By aneshdas in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-08-2014, 01:53 AM
  4. Macro to change all borders in a range of cells
    By DJFudd in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-13-2013, 01:00 AM
  5. Macro to change all borders in a range of cells
    By DJFudd in forum Outlook Formatting & Functions
    Replies: 1
    Last Post: 04-13-2013, 01:00 AM
  6. Change range of cells within VBA macro and copy and paste to fixed cell range
    By Mannyny in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-20-2012, 11:51 AM
  7. Custom change Macro's Range value, from cells input.
    By Kenji in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-17-2009, 11:54 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