+ Reply to Thread
Results 1 to 5 of 5

Selecting multiple cells

  1. #1
    Registered User
    Join Date
    06-22-2011
    Location
    Atlanta
    MS-Off Ver
    Excel 2003
    Posts
    2

    Selecting multiple cells

    Hi,

    I am new to Excel programming.

    I wanted to know if there is a way for detecting the multiple cells which i have selected in my worksheet using a macro?

    The cells can be in different rows and columns and may or may not be adjacent to each other.

    I used the Selected method but it just gives the first selected cell and not the rest of them.

    Someone might have posted a solution earlier. If so can anyone point me to it or if not can someone help me.

    Thanks,

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Selecting multiple cells

    Hello neo87,

    Could you be more specific on your request? Maybe supply the code that you already have. Do you have a specific example you could give us so we understand better?

    From first glance it sounds like you are trying to select multiple cells. While not the best example this is one way.

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    06-22-2011
    Location
    Atlanta
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Selecting multiple cells

    I meant something like

    I manually select the cells 1, 3 and 5 in Column1 and cells 2,4,6 in Column 2 in the excel sheet

    In the Macro i just created a MsgBox(Selection).

    What it does is it just gives me the value in the first cell which is Cell(1,1) and not the rest of them. I want them all as I want to create a string form the values in them and query the DB using that String.

    I don't know if I am clear enough. If I am not please let me know

    Thanks

  4. #4
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Selecting multiple cells

    While the message box is only showing you the first cells character the selection is still complete. If you wanted to display all the cells values in a message box you would need to do something like this:

    Please Login or Register  to view this content.
    I am still not sure what you are trying to do. Are you wanting to search a database for each value that you select? If so then there might be a better way to do it.

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Selecting multiple cells

    "Detect the cells"? yes, Selection will do that.
    Please Login or Register  to view this content.
    But with a multi-cell range (continuous or otherwise) getting the values of those cells into a single string would require a loop.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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