+ Reply to Thread
Results 1 to 14 of 14

VBA For every two cell group, give each cell in the group the same value.

  1. #1
    Registered User
    Join Date
    10-23-2020
    Location
    USA
    MS-Off Ver
    365
    Posts
    16

    VBA For every two cell group, give each cell in the group the same value.

    Hope I explain this well enough for some help. I have tried multiple ways of coding this with no real success, so I figured it would be best for me to explain and start from scratch.

    I have a spreadsheet with approximately 11000 rows of data. Rows 4&5 represent a group of data, 5&6 a group of data, and so on.

    For each group of rows, one of the cells in column T already has data stored. For example, in the first group (rows 4&5), cell T4 holds the data.

    However, there is not a pattern to the cells in which the data is stored, such as odd or even numbered rows. In group of rows 8&9, group T9 stores the data.

    For each group of rows, I need for each cell to hold the same number. Example: Cells T4 and T5 should both hold the value of 78 (originally found in T4) . Cells T8 and T9 should both hold the value of 100 (originally found in T9)



    Any help with this is greatly appreciated. New to VBA and struggling with where to go with this problem.

    Thanks!
    Attached Files Attached Files
    Last edited by wabrown90; 10-27-2020 at 12:22 PM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,873

    Re: VBA For every two cell group, give each cell in the group the same value.

    Please read the yellow banner at the top of this page on how to attach a file.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    10-23-2020
    Location
    USA
    MS-Off Ver
    365
    Posts
    16

    Re: VBA For every two cell group, give each cell in the group the same value.

    Quote Originally Posted by alansidman View Post
    Please read the yellow banner at the top of this page on how to attach a file.
    Thanks - corrected

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,873

    Re: VBA For every two cell group, give each cell in the group the same value.

    Your sample does not match your explanation in post #1. Additionally, you have not provided a mocked up solution for your example. We truly only need 8-10 records -- not 10,000. Please elaborate on your explanation to match your sample data as it does not make sense currently.

  5. #5
    Registered User
    Join Date
    10-23-2020
    Location
    USA
    MS-Off Ver
    365
    Posts
    16

    Re: VBA For every two cell group, give each cell in the group the same value.

    Quote Originally Posted by alansidman View Post
    Your sample does not match your explanation in post #1. Additionally, you have not provided a mocked up solution for your example. We truly only need 8-10 records -- not 10,000. Please elaborate on your explanation to match your sample data as it does not make sense currently.
    I had to delete the remainder for confidentiality purposes. The groupings still apply (rows 2&3, 4&5, etc. as groups).

  6. #6
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,077

    Re: VBA For every two cell group, give each cell in the group the same value.

    How about
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    10-23-2020
    Location
    USA
    MS-Off Ver
    365
    Posts
    16

    Re: VBA For every two cell group, give each cell in the group the same value.

    Quote Originally Posted by Fluff13 View Post
    How about
    Please Login or Register  to view this content.
    Fluff - this worked perfectly. Thank you for the help!

    If you don't mind - could you explain this line of code? Still new to much of this.

    .SpecialCells(xlBlanks).FormulaR1C1 = "=if(iseven(row()),r[1]c,r[-1]c)"

  8. #8
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,077

    Re: VBA For every two cell group, give each cell in the group the same value.

    This part looks for all the blank cells in the range
    Please Login or Register  to view this content.
    and then it puts this formula into those cells (using R1C1 notation)
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    10-23-2020
    Location
    USA
    MS-Off Ver
    365
    Posts
    16

    Re: VBA For every two cell group, give each cell in the group the same value.

    As a followup to this - I am now operating with a different column of data, all negative numbers. I am looking to copy within the groups as above, but now turn these numbers into positive numbers. The code I am trying to use will copy the numbers exactly, but will not turn them positive. Below is the modification to the above code that I am attempting to use:


    Please Login or Register  to view this content.

  10. #10
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,077

    Re: VBA For every two cell group, give each cell in the group the same value.

    Can you please post a sample workbook along with expected results?

  11. #11
    Registered User
    Join Date
    10-23-2020
    Location
    USA
    MS-Off Ver
    365
    Posts
    16

    Re: VBA For every two cell group, give each cell in the group the same value.

    Quote Originally Posted by Fluff13 View Post
    Can you please post a sample workbook along with expected results?
    Sorry about that. Should have posted that originally.

    Rows 2 and 3 are what the expected results should be. The blank cell within the respective group (2&3, 4&5, etc.) should be the same number, but with a positive number instead of a negative.
    Attached Files Attached Files

  12. #12
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,077

    Re: VBA For every two cell group, give each cell in the group the same value.

    How about
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    10-23-2020
    Location
    USA
    MS-Off Ver
    365
    Posts
    16

    Re: VBA For every two cell group, give each cell in the group the same value.

    Quote Originally Posted by Fluff13 View Post
    How about
    Please Login or Register  to view this content.
    Fluff - you did it again! Thanks again. Pretty clear I got too carried away with the withs/loops in my attempt.

  14. #14
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,077

    Re: VBA For every two cell group, give each cell in the group the same value.

    You're welcome & thanks for the feedback.

+ 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. Generate random group of words in a cell from a large group word list in column
    By faizzsheikh in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 07-26-2018, 10:16 AM
  2. Replies: 14
    Last Post: 01-12-2017, 01:41 PM
  3. Replies: 7
    Last Post: 06-09-2016, 09:48 PM
  4. [SOLVED] (VBA) How Assign Column Cell To Corresponding Group, and Paste Group Cells into Groups WS?
    By eryksd in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-08-2016, 06:18 PM
  5. Replies: 0
    Last Post: 10-21-2014, 03:20 PM
  6. Replies: 1
    Last Post: 02-10-2014, 10:26 PM
  7. Group and give max value
    By booo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-07-2012, 01:36 PM

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