title: Stop SQL Pasting Whitespace From Excel
body: <p>I'm trying to paste columns of data at a time from Excel into SQL Server. Each cell in a column contains a formula to say that, if a certain cell in another sheet is not blank, output an SQL script. If it is blank, output a blank value (""). I select and copy this data with a button (I have a button for each column of data), before pasting it into a new query in SQL Server. The SQL script is fed the values of the cells in other sheets - each column of data represents a different sheet, and each cell in a column refers to the individual cell values in the sheet it represents.</p>
  
  <p>However, every time I paste the data, it includes the blank values, which appear as whitespace.</p>
  
  <p>I've tried reprogramming the button in VBA so that it doesn't select the cells with a blank value, but nothing has worked so far. I've used the SpecialCells method in various different ways, but without success.</p>
  
  <p>Here is an example of the current code for my buttons:</p>
  
  <pre><code>Sub SchemeCondition_Click()
  Range("E2:E201").Select
  Selection.Copy
  End Sub
  </code></pre>
  
  <p>And here is an example of the formula that I have in each cell that's being copied by the button:</p>
  
  <pre><code>=IF(SchemeCondition!A2&lt;&gt;"","USE [PRSMaster] INSERT INTO SchemeCondition
  (SchemeID, ConditionTypeID, Active, Comorbidity) VALUES(" &amp; SchemeCondition!C2 &amp; ",
  " &amp; SchemeCondition!D2 &amp; ", " &amp; SchemeCondition!E2 &amp; ", " &amp; SchemeCondition!F2 &amp; ")","")
  </code></pre>
  
  <p>I just want to stop whitespace from appearing when I paste, so that I don't have to manually remove it each time.</p>