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.
However, every time I paste the data, it includes the blank values, which appear as whitespace.
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.
Here is an example of the current code for my buttons:
Sub SchemeCondition_Click()
Range("E2:E201").Select
Selection.Copy
End Sub
And here is an example of the formula that I have in each cell that's being copied by the button:
=IF(SchemeCondition!A2<>"","USE [PRSMaster] INSERT INTO SchemeCondition
(SchemeID, ConditionTypeID, Active, Comorbidity) VALUES(" & SchemeCondition!C2 & ",
" & SchemeCondition!D2 & ", " & SchemeCondition!E2 & ", " & SchemeCondition!F2 & ")","")
I just want to stop whitespace from appearing when I paste, so that I don't have to manually remove it each time.