+ Reply to Thread
Results 1 to 10 of 10

Number each cell in a selection

  1. #1
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Number each cell in a selection

    I need some help getting the process started. I have a source workbook with Names listed in Column A of Sheet 1 from A1:A400, and in another workbook I've selected a random range,A1:K25, 275 cells. So in this instance I want to fill my range with the first 275 names from my Source workbook (if I selected a larger or smaller range of course the number would change). I thought first about doing it with a simple formula in A1 of
    "=[SourceWorkbook.xlsx]sheet1!$A1",
    then dragging down to the bottom of the first column. But then in column B I'd need to start with
    "=[SourceWorkbook.xlsx]sheet1!$A26",
    and so forth for the rest of the columns in my selection.

    Then I had the bright idea of, if I could assign each cell in my selection a number, I could plug in a formula using the cell number. Only problem is I'm stumped on how to do that programmatically.

    I've attached sample files of what I'm trying to do. I appreciate any help I can get.
    Attached Files Attached Files
    I know I'm not stupid, but I suspect I'm a lot stupider than I think I am

  2. #2
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Number each cell in a selection

    Something to consider.
    Please Login or Register  to view this content.
    In your true situation you can just paste the array in your target workbook.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  3. #3
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Number each cell in a selection

    Bakerman, I tried it, but all I got was a 2 in cells B2 and D2. I came up with a start on my own, but it's far from good. IF my selection is A1 to K25, it works like a champ. But I select, say, M15:Q27, it's writing in the my original range, so I'll have to refigure it.
    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    Re: Number each cell in a selection

    One possible solution using helper cells.
    First define your block size in cells M8 and M9.
    I used sheets 2 for source data.
    You can adjust formulas but this should get you started if you want to use formula base solution.
    1. Click on the * Add Reputation if you think this helped you
    2. Mark your thread as SOLVED when question is resolved

    Modytrane

  5. #5
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    Re: Number each cell in a selection

    Oh ! I just read your post.
    I didn't realize you wanted to define the starting position as well. I thought it was just the size with starting position in A1.

  6. #6
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Number each cell in a selection

    I think I've solved my basic issue by giving it another try. I think this will work with any range I select, but I still need to do something if the cells in my selected range outnumber my available names.
    Please Login or Register  to view this content.

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Number each cell in a selection

    Please Login or Register  to view this content.
    Open Another workbook first, then open workbook with names.
    Example: type 20 in first inputbox, 10 in second and A20 in third.

  8. #8
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Number each cell in a selection

    I've been testing this with my REAL name source (which contains 10,000 names, and so far it's working flawlessly, EXCEPT for converting my formulas to values. That part works fine EXCEPT when I try to fill disparate ranges. For instance, at one shot, filling ranges A1:C15, E7:G19, J4:J12. The fill works perfectly, but the value = value converts some of the values to NAs, so I'll have to rethink that.
    Please Login or Register  to view this content.

  9. #9
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Number each cell in a selection

    Change path to Sourceworkbook.
    Please Login or Register  to view this content.

  10. #10
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Number each cell in a selection

    Slick! Appears to be fast, and spot on. To make it work in my application I had to change the file path to use my actual source. This slowed it down a little, because the workbook it opens is pretty big. I'll have to work on that, but even with the size it currently is, your code is faster than mine, so i'll move in this direction. Thanks so much for the input!
    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. Randon Number Selection formula that excludes previously selected number
    By lhousesoccer in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-25-2014, 05:52 PM
  2. Selection from cell to certain number/date in that row
    By Kreppie in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-25-2014, 04:03 AM
  3. Cell offset based on number of cells in selection
    By jerrydiaz in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 04-17-2014, 09:27 AM
  4. Replies: 3
    Last Post: 01-31-2013, 09:38 PM
  5. [SOLVED] Increase number value of cell from dual combobox selection
    By Karithina in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-24-2012, 02:53 AM
  6. Replies: 3
    Last Post: 09-20-2012, 03:11 PM
  7. selection.find - write a number in the cell next to found cell
    By Sir_Nemo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-10-2012, 07:29 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