View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson[_4_] Jim Thomlinson[_4_] is offline
external usenet poster
 
Posts: 1,119
Default Output to a file?

Give this code a try. To use ti you must reference it to "Microsoft Scripting
Runtime"
(Tools - References...)

Sub CreateSelects()
Dim fso As FileSystemObject
Dim fsoFile As Variant
Dim wks As Worksheet
Dim rngToTraverse As Range
Dim rngCurrent As Range

Set wks = Sheets("Sheet1")
Set rngToTraverse = wks.Range(wks.Range("A2"), _
wks.Cells(Rows.Count, "A").End(xlUp))

Set fso = New FileSystemObject
Set fsoFile = fso.CreateTextFile("C:\Output.txt")

For Each rngCurrent In rngToTraverse
If rngCurrent.Value < Empty Then _
fsoFile.writeline "SELECT " & rngCurrent.Value & _
" FROM " & rngCurrent.Offset(0, 1).Value & " ..."
Next rngCurrent
fsoFile.Close
Set fsoFile = Nothing
Set fso = Nothing
End Sub

Since I do not know which columns to use you will have to modify the code to
suit your needs...
--
HTH...

Jim Thomlinson


"Kevin Burton" wrote:

This is my first attempt at programming Excel so please bear with me.
I have a sheet (Sheet3 named "Columns"). On this sheet there are three
columns that I am interested in Table, CodeColumn, Column. Where ever the
value in CodeColumn is not blank I want to form:

SELECT "Column" FROM "Table" WHERE "Column" NOT IN (SELECT "Column" FROM
"CodeColumn")

The quoted names would be the values in the spread sheet. In the end I would
end up with a text file that has the above formated text for each line that
CodeColumn is not blank.

Is this hard? First I am not sure how to specify the sheet, next I don't
know how to iterate through each row in the sheet, and I am not sure how to
output the data to a file (I would be happy with the lines in the clipboard
if that was easiest).

Thank you in advance for your help even if it is just to get me started.

Kevin Burton