Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Output to a file?

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Output to a file?

Thank you. This definitely got me started.
This line is causing some problem:

Set wks = Sheets("Sheet1")

When I try to run this I get an error "Method 'Sheets' of object _Global
failed."

For my spread sheet (.xls file) this is Sheet3 with a name of "Columns" I am
guessing that I should rename this to "Sheet3".

Finally I am not sure what the syntax around rngCurrent.Offset(0, 1).Value is.
I am interested in columns A, I, and J. You set rngToTraverse to column 'A'
starting at row 2. I am interested in the non blank column at 'I'. If I
change the 'A' to 'I' so it looks like:

Set rngToTraverse = wks.Range(wks.Range("I2"), _
wks.Cells(Rows.Count, "I").End(xlUp))

As I understand it when the test for a non empty cell to reference column
'A' I would input an Offset(0,-8) right?

Thanks again.

Kevin

"Jim Thomlinson" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Output to a file?

For the most part you have it...

set wks = sheets("Sheet1")
Since I did not know which sheet it is that your list is on I made it
variable. "Sheet1" is the tab name, so if your tab is "Columns" then you want
set wks = Columns("Sheet1")

You could also just use

set wks = sheet3 'where sheet3 is the code name

rngCurrent is a range object that is traversing A2 throught A??. Change it
to I if that is what you need. The offset is just a way of looking outside
the current cell. The format is row, column. The values can be + or -, just
be sure not to offset right off of the worksheet or you will receive a run
time error. It looks like you have this correct in your assesment.
--
HTH...

Jim Thomlinson


"Kevin Burton" wrote:

Thank you. This definitely got me started.
This line is causing some problem:

Set wks = Sheets("Sheet1")

When I try to run this I get an error "Method 'Sheets' of object _Global
failed."

For my spread sheet (.xls file) this is Sheet3 with a name of "Columns" I am
guessing that I should rename this to "Sheet3".

Finally I am not sure what the syntax around rngCurrent.Offset(0, 1).Value is.
I am interested in columns A, I, and J. You set rngToTraverse to column 'A'
starting at row 2. I am interested in the non blank column at 'I'. If I
change the 'A' to 'I' so it looks like:

Set rngToTraverse = wks.Range(wks.Range("I2"), _
wks.Cells(Rows.Count, "I").End(xlUp))

As I understand it when the test for a non empty cell to reference column
'A' I would input an Offset(0,-8) right?

Thanks again.

Kevin

"Jim Thomlinson" wrote:

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Output to a file?

Now I have:

Dim fso As FileSystemObject
Dim fsoFile As Variant
Dim wks As Worksheet
Dim rngToTraverse As Range
Dim rngCurrent As Range

Set wks = Columns("Sheet1")
Set rngToTraverse = wks.Range(wks.Range("I2"), _
wks.Cells(Rows.Count, "I").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.Offset(0, 1).Value & _
" FROM " & rngCurrent.Offset(0, -8).Value & _
" WHERE " & rngCurrent.Offset(0, 1).Value & " NOT IN " & _
"(SELECT " & rngCurrent.Offset(0, 1).Value & " FROM " & rngCurrent.Value & ")"
Next rngCurrent
fsoFile.Close
Set fsoFile = Nothing
Set fso = Nothing

But the line

Set wks = Columns("Sheet1")

Gives me an error "Runtime error '13': Type mismatch

I think I have not communicated the structure of the Excel document
correctly. I have a file (call it Changes.xls). In that file there are four
tabs (sheets?) at the bottom the sheet that I am interested in is named
"Columns" it is sheet3.

Thank you.

Kevin

"Jim Thomlinson" wrote:

For the most part you have it...

set wks = sheets("Sheet1")
Since I did not know which sheet it is that your list is on I made it
variable. "Sheet1" is the tab name, so if your tab is "Columns" then you want
set wks = Columns("Sheet1")

You could also just use

set wks = sheet3 'where sheet3 is the code name

rngCurrent is a range object that is traversing A2 throught A??. Change it
to I if that is what you need. The offset is just a way of looking outside
the current cell. The format is row, column. The values can be + or -, just
be sure not to offset right off of the worksheet or you will receive a run
time error. It looks like you have this correct in your assesment.
--
HTH...

Jim Thomlinson


"Kevin Burton" wrote:

Thank you. This definitely got me started.
This line is causing some problem:

Set wks = Sheets("Sheet1")

When I try to run this I get an error "Method 'Sheets' of object _Global
failed."

For my spread sheet (.xls file) this is Sheet3 with a name of "Columns" I am
guessing that I should rename this to "Sheet3".

Finally I am not sure what the syntax around rngCurrent.Offset(0, 1).Value is.
I am interested in columns A, I, and J. You set rngToTraverse to column 'A'
starting at row 2. I am interested in the non blank column at 'I'. If I
change the 'A' to 'I' so it looks like:

Set rngToTraverse = wks.Range(wks.Range("I2"), _
wks.Cells(Rows.Count, "I").End(xlUp))

As I understand it when the test for a non empty cell to reference column
'A' I would input an Offset(0,-8) right?

Thanks again.

Kevin

"Jim Thomlinson" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Open a print output sent to file Ted Johnston Excel Discussion (Misc queries) 0 February 24th 06 10:10 AM
Cannot open file for output DavidTM Excel Programming 1 September 27th 05 09:26 AM
CSV output file Suzanne[_5_] Excel Programming 2 March 4th 05 05:03 PM
VBA help to output a file Paula Weill Excel Programming 2 September 20th 04 02:12 PM
Trying to protect output file with Macro Vasant Nanavati Excel Programming 0 June 2nd 04 01:23 AM


All times are GMT +1. The time now is 08:48 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"