Closed Thread
Results 1 to 15 of 15

Replace diagonal value in a sequence

  1. #1
    Registered User
    Join Date
    03-20-2022
    Location
    Seoul
    MS-Off Ver
    2016
    Posts
    6

    Smile Replace diagonal value in a sequence


    I'd like to replace the 1's in these matrixes in Sheet3 with values from the "age" row in Sheet2. Each matrix would be assigned one number.
    So the 1's in the top matrix would be assigned 59, and the 1's in the second matrix would be assigned 51.
    I would like to repeat this process with all values from the "age" row.

    From what I'm gathering, this can only be done with VBA. I'd appreciate your help!

    Thanks so much!


    age.png
    matrix.png

    I want to create this:

    matrix result.png
    Last edited by ohnewbie; 03-20-2022 at 12:15 PM.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Replace diagonal value in a sequence

    Hi ohnewbie and welcome to the forum,

    Have you tried to select the range and perform a Search and Replace? It will only replace in the selected range. If that doesn't work then we need to see a sample workbook
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    03-20-2022
    Location
    Seoul
    MS-Off Ver
    2016
    Posts
    6

    Re: Replace diagonal value in a sequence

    Thanks MarvinP! That is one option but I have over 600 observations I would have to search and replace. I'd like to attach a link to my workbook but this forum is not permitting me to share a link

    The matrix is 22 X 22. There are over 600 matrixes. One matrix per observation.

    Since I cannot attach a sample workbook, I'm pasting ages from 20 respondents.

    age:

    59
    51
    58
    41
    43
    46
    38
    28
    44
    42
    47
    35
    37
    30
    27
    52
    57
    42
    40
    56
    Attached Files Attached Files
    Last edited by ohnewbie; 03-20-2022 at 12:57 PM.

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Replace diagonal value in a sequence

    Hey oh,

    I need a better example to see how the data is arranged and why 59 or 51? Also is "1" the only numbers that appear in all matrices that need replacing and "1" doesn't appear anywhere else? We need a sample workbook to understand the problem better.

  5. #5
    Registered User
    Join Date
    03-20-2022
    Location
    Seoul
    MS-Off Ver
    2016
    Posts
    6

    Re: Replace diagonal value in a sequence

    Thanks Marvin! I edited my previous post with an attachment to a sample workbook. I replaced the values in the first three matrices to show what I'm trying to achieve. Each color block represents one observation.

    I'm trying to generate a matrix per observation in which the age value runs diagonally through the matrix.
    The data has to be formatted this way for my analysis in R.
    Attached Files Attached Files
    Last edited by ohnewbie; 03-20-2022 at 01:20 PM.

  6. #6
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,053

    Re: Replace diagonal value in a sequence

    OK. Cut and paste won't work for sure!!

    In A2, copied across and then down... and down..

    =IF(1+MOD((ROWS(A$2:A2)-1),22)=COLUMNS($A2:A2),INDEX(Sheet2!$B$1:$YO$1,,1+INT((ROWS(A$2:A2)-1)/22)),0)

    Fortunately, I have O365 and was able to copy it all the way to the bottom much more asily than you could... so I did it for you. The file has had to be zipped to get it onto the Forum.
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  7. #7
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,236

    Re: Replace diagonal value in a sequence

    May I ask ... why replace 1's when all you can do is just overwrite data...
    Please Login or Register  to view this content.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  8. #8
    Registered User
    Join Date
    03-20-2022
    Location
    Seoul
    MS-Off Ver
    2016
    Posts
    6

    Re: Replace diagonal value in a sequence

    Thanks so much Glenn! Trouble is, I have to repeat this process for other variables. Does only O365 allow you to do what you did?

  9. #9
    Registered User
    Join Date
    03-20-2022
    Location
    Seoul
    MS-Off Ver
    2016
    Posts
    6

    Re: Replace diagonal value in a sequence

    Thank you so much Sintek! I didn't realize that was possible.

    I think I can follow most of the code, but there are couple parts I don't understand.
    "Sheet1.Range("A2").Resize(x, 22).Value = Temp" Where does Sheet1 come from? And what does Temp represent?

  10. #10
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,053

    Re: Replace diagonal value in a sequence

    Nothing there that requires O365. It was a quick way of copying the values down. That's all

  11. #11
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,236

    Re: Replace diagonal value in a sequence

    Quote Originally Posted by ohnewbie View Post
    Thank you so much Sintek! I didn't realize that was possible.

    I think I can follow most of the code, but there are couple parts I don't understand.
    "Sheet1.Range("A2").Resize(x, 22).Value = Temp" Where does Sheet1 come from? And what does Temp represent?
    Your Sheet3 is in actual fact Sheet1 in index...
    Temp refers to the Array that stored the data

  12. #12
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,053

    Re: Replace diagonal value in a sequence

    You're welcome.



    It would be very nice if you were to just click the Add Reputation button at the foot of any of the posts of members who helped you reach a solution.

    Finally, if that takes care of your original question, please select "Thread Tools" from the menu link (just above the first post in the thread) and mark this thread as SOLVED.

  13. #13
    Registered User
    Join Date
    03-20-2022
    Location
    Seoul
    MS-Off Ver
    2016
    Posts
    6

    Re: Replace diagonal value in a sequence

    Thank you so much Glenn and Sintek!

  14. #14
    Registered User
    Join Date
    12-20-2022
    Location
    nashik,india
    MS-Off Ver
    2016
    Posts
    1

    Re: Replace diagonal value in a sequence

    hello sir,
    i am trying to use this formula row wise but not working.

  15. #15
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,053

    Re: Replace diagonal value in a sequence

    Hi.

    It's a forum rule that you start your own thread, rather than "piggy-backing" on someone else's thread. This helps prevent massive confusion arising - which will happen if it is not clear which question is being answered. So please start your own thread and explain your own problem (make sure that, right from the start, you use a meaningful title (NOT things like "help needed" or "urgent problem"... think of the Google search terms that you would use to find the solution).

    A picture is worth 1,000 words. An Excel sheet is worth 1,000 pictures. So, prepare a SMALL sample sheet (10-20 rows, not thousands!!!). Make sure there is enough data to demonstrate your need. Make sure your desired results are shown, mock them up manually if necessary. Remember to remove ALL confidential information first!!!


    The yellow banner about sample worksheets, at the top of the screen tells you how to post a sheet here on the Forum.

    Thread CLOSED.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replace hyphenated sequence with incremental numbers
    By DAVEP1985ORT in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-03-2021, 10:24 AM
  2. [SOLVED] Separate sequence of numbers with sequence of letters
    By dell001 in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 07-02-2020, 07:09 AM
  3. Find a short-sequence in a longer sequence (Clash Royale Chests Challenge)
    By GeneralDisarray in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-08-2016, 12:20 PM
  4. Replies: 7
    Last Post: 06-08-2015, 08:39 AM
  5. Replies: 0
    Last Post: 12-12-2012, 06:39 PM
  6. [SOLVED] Diagonal between cells
    By CarltonOB in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 06-24-2012, 08:16 AM
  7. text diagonal
    By Sunantoro in forum Excel General
    Replies: 5
    Last Post: 08-25-2005, 09:05 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