+ Reply to Thread
Results 1 to 10 of 10

Format cell based on data in 2 other cells

  1. #1
    Registered User
    Join Date
    03-26-2012
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 16.34 (20020900)
    Posts
    23

    Question Format cell based on data in 2 other cells

    I am trying to write a VBA macro which colours one cell (E) based on the data in two other cells (A) and (C). The macro keep falling over on the Set wsData line, generating an RTE 9 - subscript out of range error

    Here is the code

    Please Login or Register  to view this content.
    Any help gladly accepted
    Attached Files Attached Files
    Last edited by honkin; 11-20-2022 at 11:49 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,421

    Re: Format cell based on data in 2 other cells

    Subscript out of range means the sheet/tab name is not found. Check the tab name is spelt exactly the same, and for leading or trailing spaces.

    Or, you could double click on the tab name, copy it, and paste it into your code.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    03-26-2012
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 16.34 (20020900)
    Posts
    23

    Re: Format cell based on data in 2 other cells

    Quote Originally Posted by TMS View Post
    Subscript out of range means the sheet/tab name is not found. Check the tab name is spelt exactly the same, and for leading or trailing spaces.

    Or, you could double click on the tab name, copy it, and paste it into your code.
    Cheers and thanks for your reply TMS

    No, the sheet is correctly named, no spaces or anything else, but maybe the workbook needs to be defined. it is a workbook with 10 sheets in it. The workbook's name is Predictology-Reports Football Advisor.xlxs I mean, it should work with thisWorkbook.Worksheets etc, as it is the only workbook open and the sheet I am in is Lay The Draw, but maybe it needs
    Please Login or Register  to view this content.
    I am unsure, as much of the code was not compiled by me.

    I tried adding that line to the beginning of the code, but it still fell over on the same line

    So I'm kind of stuck

    Oh, forgot to add this is in Excel for MacOS. Not sure if that makes a difference.
    Last edited by honkin; 11-20-2022 at 11:37 PM.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,421

    Re: Format cell based on data in 2 other cells

    Fast answers need visual help. Please read the yellow banner at the top of this page on how to attach a file and a mocked up solution.

  5. #5
    Forum Contributor
    Join Date
    08-27-2015
    Location
    Singapore
    MS-Off Ver
    Office 2010, Office 365
    Posts
    158

    Re: Format cell based on data in 2 other cells

    Try using this instead. If it still doesn't work, maybe you need to show us the sample file without all those sensitive information so we can help.

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    03-26-2012
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 16.34 (20020900)
    Posts
    23

    Re: Format cell based on data in 2 other cells

    I have added a sample file to the original post. It has the rows just as in the original sheet.

    The idea behind it is that if column A has LTD1_HOME or LTD1_HOME_SUMMER in (that is why it lists LTD1_HOME*) and column C has any of the leagues showing in the original post, the the corresponding cell in E will turn green

    I hope that helps

    Cheers
    Last edited by honkin; 11-20-2022 at 11:52 PM.

  7. #7
    Forum Contributor
    Join Date
    08-27-2015
    Location
    Singapore
    MS-Off Ver
    Office 2010, Office 365
    Posts
    158

    Re: Format cell based on data in 2 other cells

    Are we looking at the correct file? There isn't any error on my screen.

    In your example, (Norway: Eliteserien) from column C won't highlight in column E. Is there typo error with extra T or it's correct?
    Last edited by seercoven; 11-24-2022 at 09:25 PM.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,421

    Re: Format cell based on data in 2 other cells

    I've added your code into the sample file and removed some blank lines (just for my benefit).

    It runs through and colours cells, although I don't know if they are correct.

    All looks good to me.

  9. #9
    Registered User
    Join Date
    03-26-2012
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 16.34 (20020900)
    Posts
    23

    Re: Format cell based on data in 2 other cells

    Quote Originally Posted by TMS View Post
    I've added your code into the sample file and removed some blank lines (just for my benefit).

    It runs through and colours cells, although I don't know if they are correct.

    All looks good to me.
    Cheers TMS

    It looks fine in that file, but when I copy your code and replace what I had with yours, it falls over on exactly the same line with the same RTE.

    I have tried removing the name Lay The Draw and typing it in again, but it still does exactly the same.

    I then tried saving the original file as a Macro Enabled workbook and copied the macro into a new module in that file rather than just into the Personal Workbook and it works, so that'll do for me. It also seems that the original code was correct as well. It just needed the file to be Macro Enabled and possibly to be in the module section of the file.

    Thanks so much for all your help. How do I will mark this as solved?

    cheers

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,421

    Re: Format cell based on data in 2 other cells

    You're welcome. Thanks for the rep.

    Try changing this:
    Please Login or Register  to view this content.
    to 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. Replies: 1
    Last Post: 02-02-2021, 06:11 AM
  2. Replies: 6
    Last Post: 12-04-2020, 04:37 PM
  3. Format cells based on 2 separate cell data, incorporated into the format
    By Laur_E in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-11-2019, 01:57 AM
  4. Changing Cell format based on another cells format.
    By MrStevie in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-05-2017, 03:02 PM
  5. Format cell based on 2 cells
    By ChrisGranco in forum Excel General
    Replies: 2
    Last Post: 11-06-2013, 05:56 PM
  6. [SOLVED] Macro to split cell data across multiple cells based on format-
    By Biased Historian in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-30-2013, 12:57 PM
  7. how do i format a cell based on format of a range of cells?
    By Chris Hardick in forum Excel General
    Replies: 2
    Last Post: 04-03-2006, 03:55 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