+ Reply to Thread
Results 1 to 7 of 7

how to seperate values of each column from selection

Hybrid View

  1. #1
    Registered User
    Join Date
    07-31-2013
    Location
    Chennai, India
    MS-Off Ver
    Excel 2010
    Posts
    64

    how to seperate values of each column from selection

    Hi ,

    I have values in 4 Cols a,b,c,d and row count varies... For ex i make selection from A1 to D5

    I want values of colA1 to A5 stored Range K1
    values of colb1 to b5 stored in range K2
    values of colC1 to C5 stored in range K3 and
    values of colD1 to D5 stored in range K4..

    I need the values of each columns seperately based on the selection....Any suggestions...

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: how to seperate values of each column from selection

    Not sure what you mean when you say you want values of col A1 to A5 stored Range K1... Do you mean you want the cell values concatenated?

    Can you attach a workbook showing an example of what your required outcome looks like.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Registered User
    Join Date
    07-31-2013
    Location
    Chennai, India
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: how to seperate values of each column from selection

    Hi Olly,

    I have attached an img that shows the output i require..

    Based on the selection from colA to Col D which is always static, i need to concatenate the values of each column from selection(A, b,c,d) to k1,k2,k3,k4...
    Sample_img.png

    Note: Only Numbers should not have double quotes.. Pls suggest

  4. #4
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: how to seperate values of each column from selection

    Try the following code:
    Sub foo()
    Dim lCol As Long, c As Range, stOutput As String
    For lCol = 1 To Selection.Columns.Count
        For Each c In Selection.Columns(lCol).Cells
            If IsNumeric(c.Value) Then
                stOutput = stOutput & "," & c.Value
            Else
                stOutput = stOutput & ",""" & c.Value & """"
            End If
        Next c
        If stOutput <> "" Then stOutput = Right(stOutput, Len(stOutput) - 1)
        Range("K" & lCol).Value = stOutput
        stOutput = ""
    Next lCol
    End Sub

  5. #5
    Registered User
    Join Date
    07-31-2013
    Location
    Chennai, India
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: how to seperate values of each column from selection

    Thank you... it works great..

  6. #6
    Registered User
    Join Date
    07-31-2013
    Location
    Chennai, India
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: how to seperate values of each column from selection

    Hi Olly,

    it is possible to have the output as Var Name=("aaaa","bbbb","cccc");

    attached sample imaage.. Pls suggestSampl1.png

  7. #7
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: how to seperate values of each column from selection

    Yes, just change this line:
    Range("K" & lCol).Value = stOutput
    to
    Range("K" & lCol).Value = "Var " & Cells(1, Selection.Columns(lCol).Column) & "=(" & stOutput & ");"

+ 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. [SOLVED] Counting Multiple Values in a column based on critera in seperate column
    By ERoberts in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-11-2013, 01:08 PM
  2. Replies: 0
    Last Post: 01-24-2013, 02:10 PM
  3. Replies: 1
    Last Post: 06-30-2012, 01:45 PM
  4. Replies: 29
    Last Post: 03-14-2012, 02:51 PM
  5. Averaging values based on seperate column values
    By beng404 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-16-2011, 10: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