title: How do I trim unused commas in a string with VBA
body: <p>I am writing code for a command button on an excel sheet that will take data from an input sheet and transfer it to a different workbook template. </p>
  
  <p>I have 6 possible input sections (in one section) x1-x6 that a user can put data in. When I hit the command button I want this to copy and then paste, in a designated cell on a different sheet, the data from those 6 inputs (if there is any). </p>
  
  <p>Here is where my question comes in: I have the copy &amp; paste thing figured out and the concatenate part but what I am not able to figure out is how to remove the extra commas if a user only put in x1 and x2 and leaves the rest blank. </p>
  
  <p>Basically I'm trying to trim the commas from the end of the line and stopping at the first non-comma character, does that make sense? I'll put the code and sample output in to help out </p>
  
  <pre><code>Private Sub CommandButton1_Click()
  Dim x1, x2, x3, x4, x5, x6, X As String
  Dim HData As Worksheet
  Dim Sdata as Workbook
  
  Worksheets("Information").select
  x1 = Range("B1").Value
  x2 = Range("B2").Value
  x3 = Range("B3").Value
  x4 = Range("B4").Value
  x5 = Range("B5").Value
  x6 = Range("B6").Value
  X = x1 + ", " &amp; x2 + ", " &amp; x3 + ", " &amp; x4 + ", " &amp; x5 + ", " &amp; x6
  
  'lots of code between here and the next part'
  
  .Offset(1,1) = X
  </code></pre>
  
  <p>OUTPUT <code>sample1, sample2, , , ,</code> &lt;-- I dont want these commas to show up if there is no data entered in the input section for those cells (or no commas at all if nothing is entered)...</p>