Results 1 to 9 of 9

select cells and create string

Threaded View

  1. #1
    Forum Contributor
    Join Date
    05-14-2007
    Location
    London
    MS-Off Ver
    office 365
    Posts
    118

    select cells and create string

    Hi a excel expert on here kindly provided the code below, I select cells by clicking into cells then right click and then paste string into another cell.

    Only thing is the output shows ()|()|()|() it is not picking up contents of each cell can anyone see if i am doing something wrong or there is an issue with the code - thank you

    Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
    
    '# Note that you must enable Tools > References > Microsoft Forms 2.0 Object Library
    
    '#
    '# declare
    '#
        Dim strOutput As String
        Dim lngColumnNumber As Long
        Dim lngRowNumber As Long
        Dim wsActive As Worksheet
        Dim objData As New DataObject
        
    '#
    '# initialize
    '#
        Set wsActive = Target.Parent
        
    '#
    '# build output string
    '#
        With wsActive
            For lngColumnNumber = Target.Column To (Target.Column + Target.Columns.Count)
                For lngRowNumber = Target.Row To (Target.Row + Target.Rows.Count)
                    strOutput = strOutput & "|" & .Cells(1, lngColumnNumber).Value & "(" & .Cells(lngRowNumber, lngColumnNumber).Value & ")"
                Next lngRowNumber
            Next lngColumnNumber
        End With
        
    '#
    '# copy string to the clipboard
    '#
        objData.SetText Mid$(strOutput, 2)
        objData.PutInClipboard
        Set objData = Nothing
            
    '#
    '# cancel the right click event
    '#
        Cancel = True
        
    End Sub
    Last edited by censura; 08-07-2015 at 07:38 AM. Reason: code tags

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Select only filled cells of a column and create a text file
    By Sam9 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-03-2013, 08:27 AM
  2. Concatenating the contents of several cells in a select and then copying that string
    By HorsePop in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-01-2013, 05:36 AM
  3. [SOLVED] Loop through cells and create string
    By pablowilks in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-26-2012, 12:02 PM
  4. How do I select all (of a certain string) and also the 2 cells to the right of those
    By taylormade in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-03-2012, 05:24 PM
  5. Create single string for address from multiple cells
    By level3ninja in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-28-2011, 08:45 PM
  6. Select Cells, Place Object, Create Sum Box
    By koticphreak in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-19-2008, 01:44 PM
  7. [SOLVED] [SOLVED] Select group of cells and create arrow pointer to elsewhere
    By excel frames in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-17-2006, 06:25 PM
  8. [SOLVED] How do I use 3 cells to create the string for a lookup function?
    By Bencomo in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-15-2005, 03:07 AM

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