1

I have column in excel with values like this:

Column_Name
row1
row2
row3

and I need create a string variable from that by VBA in this format

('row1','row2','row3')

I have this code

   Dim Strg As String
   With Range(Range("E2"), Range("E2").End(xlDown))
      Strg = Replace(Application.Trim(Join(Application.Transpose(.Value), " ")), " ", ",")
   End With

But it gives me only row1,row2,row3 I don't know How to put it in between ' ' and add parentheses to the beginning and end. Do you have any idea?

1 Answer 1

2

Is this what you are trying?

Dim Strg As String
With Range(Range("E2"), Range("E2").End(xlDown))
    Strg = Replace(Application.Trim(Join(Application.Transpose(.Value), " ")), " ", "','")
End With

Debug.Print "('" & Strg & "')"
Sign up to request clarification or add additional context in comments.

2 Comments

No, this give me ('row1,row2,row3') and i need ('row1','row2','row3'). The ' must be between each row, not just begginig and end
Are you sure you copied the code as I pasted it? I think you missed the the "','" part :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.