+ Reply to Thread
Results 1 to 12 of 12

Code to write to a cell on another sheet

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-16-2010
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    161

    Re: Code to write to a cell on another sheet

    Richard

    I can't have a formula in N15 on Sheet I4 as I also need to be able to manually type 'Y' in certain scenarios

    In Cricket, test match (which this is for), 2 teams have 2 innings. Team A bats (sheet I1), then Team B bats (Sheet I2), but if they don't get within 200 of the Team A's score, they 'follow on' and bat again, so Team B will be on Sheet I3 in this scenario.
    If they were all out in their 2nd Innings and still failed to match Team A's score with their combined scores from 2 innings, the match is won by Team A and I would write Y to Cell N15 on I3, which then I want to trigger this event to write Y to N15 on sheet I4 to trigger other formulae to write results etc.

    If Team B had surpassed the score of Team A with their combined scores, then Team A would bat again (Sheet I4), and N15 on I3 is ignored (I don't write to the cell), and I would then want to write to Cell N15 on sheet I4 once the game is over!!

  2. #2
    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: Code to write to a cell on another sheet

    Hello Neil,

    This explanation reminds me of the well known humorous explanation of the rules of cricket to a foreigner

    Can you upload the workbook with some typical results and indicate which are the results cells and some notes as to how you've arrived at them with reference to the contributory cells.

    Since you can't use a cell for both a formula and manually overwriting it with a constant you will need to use a Sheet Change event macro.
    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.

  3. #3
    Forum Contributor
    Join Date
    06-16-2010
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    161

    Re: Code to write to a cell on another sheet

    Quote Originally Posted by Richard Buttrey View Post
    Hello Neil,

    This explanation reminds me of the well known humorous explanation of the rules of cricket to a foreigner

    Can you upload the workbook with some typical results and indicate which are the results cells and some notes as to how you've arrived at them with reference to the contributory cells.

    Since you can't use a cell for both a formula and manually overwriting it with a constant you will need to use a Sheet Change event macro.
    Richard
    Here is a sample of the workbook, using the scenario where Team A bats first, then Team B, who fail to meet the follow on target, so bat again, and also fail to match Team A with the combined scores, ending the match.
    Thus the sheets are as follows:
    I1 = Team A
    I2 = Team B
    I3 = Team B
    I4 = Team A (unused due to the above conditions)

    A 'normal' match would be
    I1 = Team A
    I2 = Team B
    I3 = Team A
    I4 = Team B

    So, when you look, it's basically a score card for 4 innings of a Cricket test match.
    My main objective when I posted, was in this scenario, on sheet I3, if the match has finished as described above, 'Y' is entered to Cell N15 on sheet I3 (coloured red), and I want to then write that 'Y' to Cell N15 on sheet I4 (coloured yellow).
    Eventually I will use this to write results.

    Having seen the 'What happens if it rains' comment, I might also want to add a 'Y' on either Sheet I1 or I2 if the match is abandoned because of weather.
    So! Can the 'code' be used to check for a 'Y' in N15 on either Sheet I1, 2 or 3 then write it to N15 on I4

    Test Match.xlsx

  4. #4
    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: Code to write to a cell on another sheet

    Hi,

    I've added a small macro to the Workbook Sheet Change event and also named the N15 cells 'Over'

    When you enter a Y in any of the N15 cells Sheet I4 will also be updated. If you delete a Y so too will Sheet I4 have N15 cleared.
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    06-16-2010
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    161

    Re: Code to write to a cell on another sheet

    Quote Originally Posted by Richard Buttrey View Post
    Hi,

    I've added a small macro to the Workbook Sheet Change event and also named the N15 cells 'Over'

    When you enter a Y in any of the N15 cells Sheet I4 will also be updated. If you delete a Y so too will Sheet I4 have N15 cleared.
    Richard,

    Many thanks.
    At first it wasn't working, the first N15 cell I tried on Sheet I1 came up with a debug error when writing Y or deleting it.
    I noticed that cell didn't have the name 'Over' like the others, and once added it fixed it

    Thanks again.
    Neil

+ 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: 6
    Last Post: 07-18-2013, 02:34 AM
  2. Code to write formula in 2 cells, copy, paste values, repeat next row until end of sheet
    By Oly Steel Man in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-14-2013, 11:13 AM
  3. [SOLVED] Code to evaluate contents of one cell then write new values into new cell (Simple IF Stmt)
    By clemsoncooz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-05-2012, 11:54 AM
  4. Code to write in specific cell
    By fatalcore in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 07-09-2011, 03:06 PM
  5. Macro creating new worksheet. Is it possible to write running code for sheet
    By Kernal87 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-30-2008, 06:17 AM

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