Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default Data available for plotting vs already plotted data

Hello --

This charting application has the following features:

1 - user can "import" a time series (into a set of columns in a worksheet);
the app automatically adds a plot of the data to the chart

2 - user can delete from the chart a series which was plotted in 1; the
source data is not deleted from the worksheet which holds it

3 - user can decide later to add to the chart a series deleted in 2

Problem:
I want to present in a listbox the names/legends of the "imported but not
plotted" series so the user can select one for 3

If I could use SQL in this app, the source for the listbox would look
something like:

SELECT name_Imported FROM tblImported
WHERE name_Imported NOT IN (SELECT name_Plotted FROM tblPlotted)

Example:
Imported Plotted
------------ ----------
series1 series1
series2 series4
series3
series4
series5

The listpox would contain the values:
series2
series3
series5

Each "tbl..." would, I assume, be a range in one of the application's
worksheets, and filled by a process I don't know how to code.

Can anyone suggest how to populate such a listbox?

Thanks for any help.

Larry Mehl


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default Data available for plotting vs already plotted data

"L Mehl" wrote ...

If I could use SQL in this app, the source for the listbox would look
something like:

SELECT name_Imported FROM tblImported
WHERE name_Imported NOT IN (SELECT name_Plotted FROM tblPlotted)

Example:
Imported Plotted
------------ ----------
series1 series1
series2 series4
series3
series4
series5

The listpox would contain the values:
series2
series3
series5


The more usual SQL construct would be to use an OUTER JOIN:

SELECT T2.name_Plotted
FROM [tblImported] T1
LEFT JOIN [tblPlotted] T2
ON T1.name_Imported = T2.name_Plotted
WHERE T2.name_Plotted IS NOT NULL

You can access the data in a workbook using ADO but due to the dreaded
memory leak bug, you can't query an open workbook. Happily, the
workaround is easy enough: save a copy of the relevant worksheet(s) to
a temporary (closed) workbook and query the temp workbook.

Here's one I made earlier (you'll need to save *two* worksheets to the
temp workbook):

Option Explicit

Sub Test()

Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet
Dim Con As Object
Dim rs As Object
Dim strCon As String
Dim strPath As String
Dim strSql1 As String

' Amend the following constants to suit
Const FILENAME_XL_TEMP As String = "" & _
"delete_me.xls"
Const TABLE_NAME_CURRENT As String = "" & _
"XXX"
Const TABLE_NAME_NEW As String = "" & _
"MyNewTable"

' Do NOT amend the following constants
Const CONN_STRING_1 As String = "" & _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=<PATH<FILENAME;" & _
"Extended Properties='Excel 8.0;HDR=YES'"

' Build connection strings
strPath = ThisWorkbook.Path & _
Application.PathSeparator

strCon = CONN_STRING_1
strCon = Replace(strCon, _
"<PATH", strPath)
strCon = Replace(strCon, _
"<FILENAME", FILENAME_XL_TEMP)

' Build sql statement
strSql1 = ""
strSql1 = strSql1 & "SELECT Col1 FROM "
strSql1 = strSql1 & " [" & TABLE_NAME_CURRENT & "$]"
' strSql1 = strSql1 & " WHERE Co2=1 OR Col2=3"

' Delete old instance of temp workbook
On Error Resume Next
Kill strPath & FILENAME_XL_TEMP
On Error GoTo 0

' Save copy of worksheet to temp workbook
Set wb = Excel.Application.Workbooks.Add()
With wb
ThisWorkbook.Worksheets(TABLE_NAME_CURRENT). _
Copy .Worksheets(1)
.SaveAs strPath & FILENAME_XL_TEMP
.Close
End With

' Open connection to temp workbook
Set Con = CreateObject("ADODB.Connection")
With Con
.ConnectionString = strCon
.CursorLocation = 3
.Open
Set rs = .Execute(strSql1)
End With

Sheet1.ListBox1.List = _
Application.Transpose(rs.GetRows())

rs.Close
Con.Close

End Sub

--
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default Data available for plotting vs already plotted data

Thanks onedaywhen --

I ended up doing it in the same workbook, populating the listbox when
needed, using code similar to:

blnMatchFound = False

For aLoopDefinition 'loop through imported
'get fileNameImported
blnMatchFound = False
For bLoopDefinition 'loop through plotted
'get fileNamePlotted
If fileNameImported = fileNamePlotted Then 'filenames match
blnMatchFound = True
Exit For
End If
Next bLoopValue '.b.
If blnMatchFound = False Then
'add to listbox
End If
Next aLoopValue '.a.

L Mehl


"onedaywhen" wrote in message
om...
"L Mehl" wrote ...

If I could use SQL in this app, the source for the listbox would look
something like:

SELECT name_Imported FROM tblImported
WHERE name_Imported NOT IN (SELECT name_Plotted FROM tblPlotted)

Example:
Imported Plotted
------------ ----------
series1 series1
series2 series4
series3
series4
series5

The listpox would contain the values:
series2
series3
series5


The more usual SQL construct would be to use an OUTER JOIN:

SELECT T2.name_Plotted
FROM [tblImported] T1
LEFT JOIN [tblPlotted] T2
ON T1.name_Imported = T2.name_Plotted
WHERE T2.name_Plotted IS NOT NULL

You can access the data in a workbook using ADO but due to the dreaded
memory leak bug, you can't query an open workbook. Happily, the
workaround is easy enough: save a copy of the relevant worksheet(s) to
a temporary (closed) workbook and query the temp workbook.

Here's one I made earlier (you'll need to save *two* worksheets to the
temp workbook):

Option Explicit

Sub Test()

Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet
Dim Con As Object
Dim rs As Object
Dim strCon As String
Dim strPath As String
Dim strSql1 As String

' Amend the following constants to suit
Const FILENAME_XL_TEMP As String = "" & _
"delete_me.xls"
Const TABLE_NAME_CURRENT As String = "" & _
"XXX"
Const TABLE_NAME_NEW As String = "" & _
"MyNewTable"

' Do NOT amend the following constants
Const CONN_STRING_1 As String = "" & _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=<PATH<FILENAME;" & _
"Extended Properties='Excel 8.0;HDR=YES'"

' Build connection strings
strPath = ThisWorkbook.Path & _
Application.PathSeparator

strCon = CONN_STRING_1
strCon = Replace(strCon, _
"<PATH", strPath)
strCon = Replace(strCon, _
"<FILENAME", FILENAME_XL_TEMP)

' Build sql statement
strSql1 = ""
strSql1 = strSql1 & "SELECT Col1 FROM "
strSql1 = strSql1 & " [" & TABLE_NAME_CURRENT & "$]"
' strSql1 = strSql1 & " WHERE Co2=1 OR Col2=3"

' Delete old instance of temp workbook
On Error Resume Next
Kill strPath & FILENAME_XL_TEMP
On Error GoTo 0

' Save copy of worksheet to temp workbook
Set wb = Excel.Application.Workbooks.Add()
With wb
ThisWorkbook.Worksheets(TABLE_NAME_CURRENT). _
Copy .Worksheets(1)
.SaveAs strPath & FILENAME_XL_TEMP
.Close
End With

' Open connection to temp workbook
Set Con = CreateObject("ADODB.Connection")
With Con
.ConnectionString = strCon
.CursorLocation = 3
.Open
Set rs = .Execute(strSql1)
End With

Sheet1.ListBox1.List = _
Application.Transpose(rs.GetRows())

rs.Close
Con.Close

End Sub

--



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default Data available for plotting vs already plotted data

"L Mehl" wrote ...

Thanks onedaywhen --
I ended up doing it in the same workbook, populating the listbox when
needed, using code similar to <snip


It's good when someone takes the time to post back even if they
haven't taken your advice. So no offence to you but ...

.... I'm finding it increasingly frustrating that when people say, 'If
I could do this with SQL...', and 'I'm only doing this in Excel
because I don't have MS Access...' and I then I demonstrate to them
how to query a workbook using SQL and that one doesn't need the MS
Access application to create, maintain and query Jet ('Access')
databases and one can do all this (and I do!) with VBA code in Excel,
they up not be interested after all. I am so unappreciated, sob sob
(please - send no flowers)

--
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default Data available for plotting vs already plotted data

Not intending to add to your frustration ...

I have to confess that my Excel skills are at novice (= inefficient) level
in manipulating ranges/datasets, and other operations necessary for
charting.

I think I would be much more productive keeping the data in a SQL db and
using Excel for charting, and will have to try it once, just to be sure.

Thanks again for the code you suggested.

Larry


"onedaywhen" wrote in message
om...
"L Mehl" wrote ...

Thanks onedaywhen --
I ended up doing it in the same workbook, populating the listbox when
needed, using code similar to <snip


It's good when someone takes the time to post back even if they
haven't taken your advice. So no offence to you but ...

... I'm finding it increasingly frustrating that when people say, 'If
I could do this with SQL...', and 'I'm only doing this in Excel
because I don't have MS Access...' and I then I demonstrate to them
how to query a workbook using SQL and that one doesn't need the MS
Access application to create, maintain and query Jet ('Access')
databases and one can do all this (and I do!) with VBA code in Excel,
they up not be interested after all. I am so unappreciated, sob sob
(please - send no flowers)

--



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
Need chart of 1 data set plotted against another similar data set Steve Charts and Charting in Excel 2 April 25th 08 10:41 PM
Extra data plotted on chart Dan Charts and Charting in Excel 2 November 29th 07 01:34 PM
Filter the way data is plotted Lars Charts and Charting in Excel 3 May 4th 05 01:38 PM
Help with data not getting plotted Scott Ehrlich Excel Discussion (Misc queries) 2 January 25th 05 05:17 AM
Help with data not getting plotted Scott Ehrlich Charts and Charting in Excel 1 January 23rd 05 05:15 PM


All times are GMT +1. The time now is 10:16 PM.

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

About Us

"It's about Microsoft Excel"