+ Reply to Thread
Results 1 to 15 of 15

How to loop adding a column with row numbers beside each column in a dynamic range in

  1. #1
    Registered User
    Join Date
    09-20-2022
    Location
    Lagos, Nigeria
    MS-Off Ver
    MS Office 2013
    Posts
    11

    Exclamation How to loop adding a column with row numbers beside each column in a dynamic range in

    Good day. Been on this for more than a week and can't find a solution. New to VBA. I have a data sheet with multiple columns of data. I would like to add, beside each column, a column with the row numbers of each column, and to do this through the range till it hits an empty column. Something like below. My data looks like the first pic. I'd like a VBA that loops through that and turns it into the second pic. I currently use Excel 2013. Would be grateful for any response

    UPDATE: Apologies for posting pictures. I attached the sample workbook with the example sheets as in the pics. First two sheets are the before and after sheets. Then i added 2 more sheets to show how i'll be adding columns to the data sheet over time, so the vba needs to work for a dynamic range. Again, grateful for the responses so far

    UPDATE 24/09/22: this issue is resolved. The codes worked, thank you so much. I have an additional request: summing total for each unique value, in multiple columns. Similar to how to find for eg. sum of total sales for multiple months for a particular product. I have attached a sample sheet to explain. The update sheets are to show how thr input data worksheet would can expand over time, so the code would need to work for a dynamic range. So far working on it i've found i might need a SUMIF INDEX-MATCH array function, but i don't know how to write it. Would be grateful for any help, but the initial request in this thread is solved, grateful
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by Oraekene; 09-24-2022 at 07:16 AM.

  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,879

    Re: How to loop adding a column with row numbers beside each column in a dynamic range in

    Hi and welcome to the forum

    Pictures are of little value. Honestly, no one wants to re-type your data to try and solve your issue. Additionally, we would only be guessing at how your data was structured, ie. formulas, formatting, etc. Additionally, due to how some browsers behave, many of our members cannot see uploaded pictures/images. Please do not take this route.

    Please attach a sample file that represents what you have. The structure of your attachment should be the same structure as your actual data. Any proprietary information should be changed.

    Include in the attachment any code you're currently using (whether it works or not) and an "After" of what you wish the output to be.

    To attach a file to your post,
    click advanced (next to quick post),
    scroll down until you see "manage file",
    click that and select "add files" (top right corner).
    click "select files" find your file, click "open" click "upload" click 'done" bottom right. click "submit reply"

    Once the upload is completed the file name will appear below the input boxes in this window.
    You can then close the window to return to the new post screen.
    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
    09-20-2022
    Location
    Lagos, Nigeria
    MS-Off Ver
    MS Office 2013
    Posts
    11
    Quote Originally Posted by alansidman View Post
    Hi and welcome to the forum

    Pictures are of little value. Honestly, no one wants to re-type your data to try and solve your issue. Additionally, we would only be guessing at how your data was structured, ie. formulas, formatting, etc. Additionally, due to how some browsers behave, many of our members cannot see uploaded pictures/images. Please do not take this route.

    Please attach a sample file that represents what you have. The structure of your attachment should be the same structure as your actual data. Any proprietary information should be changed.

    Include in the attachment any code you're currently using (whether it works or not) and an "After" of what you wish the output to be.

    To attach a file to your post,
    click advanced (next to quick post),
    scroll down until you see "manage file",
    click that and select "add files" (top right corner).
    click "select files" find your file, click "open" click "upload" click 'done" bottom right. click "submit reply"

    Once the upload is completed the file name will appear below the input boxes in this window.
    You can then close the window to return to the new post screen.
    Thank you for this. I apologise for the pictures. Will attach the files

  4. #4
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: How to loop adding a column with row numbers beside each column in a dynamic range in

    Why are you quoting the entire post of alansidman immediately preceding your reply to him ?
    Unnecessary operation, it is known who you answer and what you are responding to ...
    Try:
    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: How to loop adding a column with row numbers beside each column in a dynamic range in

    Quote Originally Posted by Oraekene View Post
    Good day. Been on this for more than a week and can't find a solution. New to VBA. I have a data sheet with multiple columns of data. I would like to add, beside each column, a column with the row numbers of each column, and to do this through the range till it hits an empty column. Something like below. My data looks like the first pic. I'd like a VBA that loops through that and turns it into the second pic. I currently use Excel 2013. Would be grateful for any response
    Hello.
    "I suspect" that what you are looking for is an auxiliary step and that your main objective is another: Could you comment, then, for what other objective are you requesting this numbering of rows?...

  6. #6
    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,879

    Re: How to loop adding a column with row numbers beside each column in a dynamic range in

    @Oraekene
    Please don't quote whole posts -- it's just clutter.*If you are responding to a post out of sequence, limit quoted content to a few relevant lines that makes clear to whom and what you are responding

  7. #7
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,522

    Re: How to loop adding a column with row numbers beside each column in a dynamic range in

    People love the "Reply With Quote" Button.
    Maybe ExcelForum should have a piggy bank and every time when an unnecessary quote is done the culprit has to donate 25 cents to the piggy bank.
    Once a year at Christmas time all the monitors and administrators can have a nice get together and a good meal from it.

    Along the same lines but different!
    Please Login or Register  to view this content.
    Experience trumps academics every day of the week and twice on Sunday.

  8. #8
    Registered User
    Join Date
    09-20-2022
    Location
    Lagos, Nigeria
    MS-Off Ver
    MS Office 2013
    Posts
    11

    Re: How to loop adding a column with row numbers beside each column in a dynamic range in

    Good day. I'm attached a xls file of the sample data to my original post. Please check the attachments section, below the pictures

  9. #9
    Registered User
    Join Date
    09-20-2022
    Location
    Lagos, Nigeria
    MS-Off Ver
    MS Office 2013
    Posts
    11

    Re: How to loop adding a column with row numbers beside each column in a dynamic range in

    Thank you for the reply. You are right. Its an auxillary step. I'll list out the process step by step below.

    First this sheet is a master sheet, which summarises the ID column from other sheets. So

    1. New sheets are added to the workbook
    2. The appropriate column, in this case the ID column, column B, in each worksheet is filtered by time of access (in this case first 24 hours), sorted from earliest time of access to latest time of access, and the final IDs in the ID column are copied to the master sheet
    3. Rows numbers, used here to signify rank, are placed beside each column
    4. A final column of distinct ID numbers is generated
    5. The row numbers for each ID are then sumed up beside their values in a new column
    6. The ID numbers are then sorted by the row sums: the ID with the least sum are ranked top (i.e earliest on average) and the ID with the largest sum is ranked last (latest)

    No 3 is what i hope to achieve with this VBA. I updated my original post with a link to the sample excel sheet. Would be grateful for a response

  10. #10
    Registered User
    Join Date
    09-20-2022
    Location
    Lagos, Nigeria
    MS-Off Ver
    MS Office 2013
    Posts
    11

    Re: How to loop adding a column with row numbers beside each column in a dynamic range in

    Noted. Thank you

  11. #11
    Registered User
    Join Date
    09-20-2022
    Location
    Lagos, Nigeria
    MS-Off Ver
    MS Office 2013
    Posts
    11

    Re: How to loop adding a column with row numbers beside each column in a dynamic range in

    My bad. New to forums in general. Thank you for thr reply. Will try this code now and give feedback

  12. #12
    Registered User
    Join Date
    09-20-2022
    Location
    Lagos, Nigeria
    MS-Off Ver
    MS Office 2013
    Posts
    11

    Re: How to loop adding a column with row numbers beside each column in a dynamic range in

    Thank you for this. Realised the error after i'd posted the quote. Repliea only from now on😊 Will try out the code and give a reponse, thank you!

  13. #13
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,522

    Re: How to loop adding a column with row numbers beside each column in a dynamic range in

    Re your Post #9.
    Just let us know if the two suggestions do what you need. If not, let us know what is wrong.

  14. #14
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: How to loop adding a column with row numbers beside each column in a dynamic range in

    Hello.
    I didn't understand the relationship between your detailed explanation in post #9 and your workbook in post #1.

    That's why I am attaching a first treatment of the information in the attached workbook: every time you add a new column in the "input" sheet, you can run the macro and new information will be generated in the "result" sheet.

    If correct, indicate (on the "results" sheet itself) what you do next with that information.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    09-20-2022
    Location
    Lagos, Nigeria
    MS-Off Ver
    MS Office 2013
    Posts
    11

    Re: How to loop adding a column with row numbers beside each column in a dynamic range in

    I tried your code and it worked! Thank you! Really grateful

+ 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: 04-12-2019, 08:15 PM
  2. [SOLVED] Locating text in a column, then adding numbers from the adjacent column.
    By CertainlyIndecisive in forum Excel Formulas & Functions
    Replies: 29
    Last Post: 01-02-2018, 12:54 PM
  3. Adding sequential numbers to Column A if Column B has text
    By computer12345 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-28-2015, 09:11 AM
  4. Need to define dynamic range for column I to K based on dynamic column A
    By flabb in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-19-2015, 10:19 AM
  5. loop through range to copy row if data exists in column, then delete the column
    By wpryan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-01-2015, 05:03 PM
  6. Adding Sequential Numbers in Column B Based on Column A Values
    By habsfan1433 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-14-2014, 04:17 PM
  7. Replies: 12
    Last Post: 09-21-2012, 12:22 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