Pivot Tables - Multiple Ranges

Is there a way to use pivot tables in Excel to accomplish the same result as 
an MS-Access process to "join" two tables on matching fields?    For example, 
I have one range of data that contains employee time card information that 
includes a costing code for each time entry.   I have a separate data range 
that contains, for each costing code, one or more records containing 
percentages that are used to allocate labor to specific business units.   The 
desired result is a table or data range that contains all of the records from 
the time card range and all matching records from the allocation table.

I've been able to build the result that I want using VBA code and vlookups 
but I'm looking for a better way.  I've been researching Data consolidations 
and pivot tables with multiple ranges to see if this might work.  So far, it 
seems that these processes in Excel are simply to combining data rather than 
simulating a join.   Is there a way to do this with pivot tables or is code 
the only answer?

Thanks in advance for any input!!! 
0
Utf
4/10/2010 2:09:01 PM
excel.programming 6508 articles. 2 followers. Follow

9 Replies
946 Views

Similar Articles

[PageSpeed] 18

You might be able to adapt this to work for you.
Need to add a reference to the ADO library to your VBA project.

Tim


'***********************************
Sub TestJoin()

Const S_TEMP_1 As String = "SQLtempTable1"
Const S_TEMP_2 As String = "SQLtempTable2"

Dim oConn As New ADODB.Connection
Dim oRS As New ADODB.Recordset
Dim sPath

Dim rng1 As Range, rng2 As Range

   Set rng1 = Sheet1.Range("A1:B6")
   Set rng2 = Sheet2.Range("A1:B16")

   Dim sSQL As String

    sSQL = "select t1.ID, t1.COL1, t2.COL2 " & _
           " from SQLtempTable1 t1, SQLtempTable2 t2 " & _
           " where t1.ID = t2.ID"

   'delete the range names and re-apply
   On Error Resume Next
   ThisWorkbook.Names.Item(S_TEMP_1).Delete
   ActiveWorkbook.Names.Item(S_TEMP_2).Delete
   On Error GoTo 0
   ThisWorkbook.Names.Add Name:=S_TEMP_1, RefersToLocal:=rng1
   ThisWorkbook.Names.Add Name:=S_TEMP_2, RefersToLocal:=rng2

   sPath = ThisWorkbook.Path & "\" & ThisWorkbook.Name

   oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
              "Data Source=" & sPath & _
              ";Extended Properties=""Excel 8.0;HDR=Yes"""

   Set oRS = oConn.Execute(sSQL)

   If Not oRS.EOF And Not oRS.BOF Then
         Sheet3.Range("A2").CopyFromRecordset oRS
   Else
         MsgBox "No records found"
   End If

End Sub
'***************************************

"Gr8lyConfused" <Gr8lyConfused@discussions.microsoft.com> wrote in message 
news:41EE2F52-6C6F-4520-8AD0-CB2282FC258E@microsoft.com...
>
> Is there a way to use pivot tables in Excel to accomplish the same result 
> as
> an MS-Access process to "join" two tables on matching fields?    For 
> example,
> I have one range of data that contains employee time card information that
> includes a costing code for each time entry.   I have a separate data 
> range
> that contains, for each costing code, one or more records containing
> percentages that are used to allocate labor to specific business units. 
> The
> desired result is a table or data range that contains all of the records 
> from
> the time card range and all matching records from the allocation table.
>
> I've been able to build the result that I want using VBA code and vlookups
> but I'm looking for a better way.  I've been researching Data 
> consolidations
> and pivot tables with multiple ranges to see if this might work.  So far, 
> it
> seems that these processes in Excel are simply to combining data rather 
> than
> simulating a join.   Is there a way to do this with pivot tables or is 
> code
> the only answer?
>
> Thanks in advance for any input!!! 


0
Tim
4/10/2010 5:41:55 PM
Thanks Tim!   This is great stuff.   It looks like the modifications I would 
have to make would be in setting the ranges, tailoring the SQL select 
statement to match my data and maybe the Conn.Open statement.  

Would the ADO library be "Microsoft ADO Ext. 2.7 for DDL and Security"?   
This is the only one I could find in my available references containing 
"ADO". 

Thanks so much Tim!

Rick

"Tim Williams" wrote:

> You might be able to adapt this to work for you.
> Need to add a reference to the ADO library to your VBA project.
> 
> Tim
> 
> 
> '***********************************
> Sub TestJoin()
> 
> Const S_TEMP_1 As String = "SQLtempTable1"
> Const S_TEMP_2 As String = "SQLtempTable2"
> 
> Dim oConn As New ADODB.Connection
> Dim oRS As New ADODB.Recordset
> Dim sPath
> 
> Dim rng1 As Range, rng2 As Range
> 
>    Set rng1 = Sheet1.Range("A1:B6")
>    Set rng2 = Sheet2.Range("A1:B16")
> 
>    Dim sSQL As String
> 
>     sSQL = "select t1.ID, t1.COL1, t2.COL2 " & _
>            " from SQLtempTable1 t1, SQLtempTable2 t2 " & _
>            " where t1.ID = t2.ID"
> 
>    'delete the range names and re-apply
>    On Error Resume Next
>    ThisWorkbook.Names.Item(S_TEMP_1).Delete
>    ActiveWorkbook.Names.Item(S_TEMP_2).Delete
>    On Error GoTo 0
>    ThisWorkbook.Names.Add Name:=S_TEMP_1, RefersToLocal:=rng1
>    ThisWorkbook.Names.Add Name:=S_TEMP_2, RefersToLocal:=rng2
> 
>    sPath = ThisWorkbook.Path & "\" & ThisWorkbook.Name
> 
>    oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
>               "Data Source=" & sPath & _
>               ";Extended Properties=""Excel 8.0;HDR=Yes"""
> 
>    Set oRS = oConn.Execute(sSQL)
> 
>    If Not oRS.EOF And Not oRS.BOF Then
>          Sheet3.Range("A2").CopyFromRecordset oRS
>    Else
>          MsgBox "No records found"
>    End If
> 
> End Sub
> '***************************************
> 
> "Gr8lyConfused" <Gr8lyConfused@discussions.microsoft.com> wrote in message 
> news:41EE2F52-6C6F-4520-8AD0-CB2282FC258E@microsoft.com...
> >
> > Is there a way to use pivot tables in Excel to accomplish the same result 
> > as
> > an MS-Access process to "join" two tables on matching fields?    For 
> > example,
> > I have one range of data that contains employee time card information that
> > includes a costing code for each time entry.   I have a separate data 
> > range
> > that contains, for each costing code, one or more records containing
> > percentages that are used to allocate labor to specific business units. 
> > The
> > desired result is a table or data range that contains all of the records 
> > from
> > the time card range and all matching records from the allocation table.
> >
> > I've been able to build the result that I want using VBA code and vlookups
> > but I'm looking for a better way.  I've been researching Data 
> > consolidations
> > and pivot tables with multiple ranges to see if this might work.  So far, 
> > it
> > seems that these processes in Excel are simply to combining data rather 
> > than
> > simulating a join.   Is there a way to do this with pivot tables or is 
> > code
> > the only answer?
> >
> > Thanks in advance for any input!!! 
> 
> 
> .
> 
0
Utf
4/10/2010 10:06:02 PM
Ok, now I'm finding several ActiveX Data Object libraries.   The one that 
looks like it has real promise is "ActiveX Data Objects Recordset 2.7 
Library".  


"Gr8lyConfused" wrote:

> Thanks Tim!   This is great stuff.   It looks like the modifications I would 
> have to make would be in setting the ranges, tailoring the SQL select 
> statement to match my data and maybe the Conn.Open statement.  
> 
> Would the ADO library be "Microsoft ADO Ext. 2.7 for DDL and Security"?   
> This is the only one I could find in my available references containing 
> "ADO". 
> 
> Thanks so much Tim!
> 
> Rick
> 
> "Tim Williams" wrote:
> 
> > You might be able to adapt this to work for you.
> > Need to add a reference to the ADO library to your VBA project.
> > 
> > Tim
> > 
> > 
> > '***********************************
> > Sub TestJoin()
> > 
> > Const S_TEMP_1 As String = "SQLtempTable1"
> > Const S_TEMP_2 As String = "SQLtempTable2"
> > 
> > Dim oConn As New ADODB.Connection
> > Dim oRS As New ADODB.Recordset
> > Dim sPath
> > 
> > Dim rng1 As Range, rng2 As Range
> > 
> >    Set rng1 = Sheet1.Range("A1:B6")
> >    Set rng2 = Sheet2.Range("A1:B16")
> > 
> >    Dim sSQL As String
> > 
> >     sSQL = "select t1.ID, t1.COL1, t2.COL2 " & _
> >            " from SQLtempTable1 t1, SQLtempTable2 t2 " & _
> >            " where t1.ID = t2.ID"
> > 
> >    'delete the range names and re-apply
> >    On Error Resume Next
> >    ThisWorkbook.Names.Item(S_TEMP_1).Delete
> >    ActiveWorkbook.Names.Item(S_TEMP_2).Delete
> >    On Error GoTo 0
> >    ThisWorkbook.Names.Add Name:=S_TEMP_1, RefersToLocal:=rng1
> >    ThisWorkbook.Names.Add Name:=S_TEMP_2, RefersToLocal:=rng2
> > 
> >    sPath = ThisWorkbook.Path & "\" & ThisWorkbook.Name
> > 
> >    oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
> >               "Data Source=" & sPath & _
> >               ";Extended Properties=""Excel 8.0;HDR=Yes"""
> > 
> >    Set oRS = oConn.Execute(sSQL)
> > 
> >    If Not oRS.EOF And Not oRS.BOF Then
> >          Sheet3.Range("A2").CopyFromRecordset oRS
> >    Else
> >          MsgBox "No records found"
> >    End If
> > 
> > End Sub
> > '***************************************
> > 
> > "Gr8lyConfused" <Gr8lyConfused@discussions.microsoft.com> wrote in message 
> > news:41EE2F52-6C6F-4520-8AD0-CB2282FC258E@microsoft.com...
> > >
> > > Is there a way to use pivot tables in Excel to accomplish the same result 
> > > as
> > > an MS-Access process to "join" two tables on matching fields?    For 
> > > example,
> > > I have one range of data that contains employee time card information that
> > > includes a costing code for each time entry.   I have a separate data 
> > > range
> > > that contains, for each costing code, one or more records containing
> > > percentages that are used to allocate labor to specific business units. 
> > > The
> > > desired result is a table or data range that contains all of the records 
> > > from
> > > the time card range and all matching records from the allocation table.
> > >
> > > I've been able to build the result that I want using VBA code and vlookups
> > > but I'm looking for a better way.  I've been researching Data 
> > > consolidations
> > > and pivot tables with multiple ranges to see if this might work.  So far, 
> > > it
> > > seems that these processes in Excel are simply to combining data rather 
> > > than
> > > simulating a join.   Is there a way to do this with pivot tables or is 
> > > code
> > > the only answer?
> > >
> > > Thanks in advance for any input!!! 
> > 
> > 
> > .
> > 
0
Utf
4/10/2010 10:18:01 PM
"Microsoft ActiveX Data Objects 2.7 Library"

Earlier versions (eg. 2.5, 2.6) should also work.

Tim


"Gr8lyConfused" <Gr8lyConfused@discussions.microsoft.com> wrote in message 
news:A340C60C-8694-4753-BC2F-9A3F1ED7B1A5@microsoft.com...
>
> Ok, now I'm finding several ActiveX Data Object libraries.   The one that
> looks like it has real promise is "ActiveX Data Objects Recordset 2.7
> Library".
>
>
> "Gr8lyConfused" wrote:
>
>> Thanks Tim!   This is great stuff.   It looks like the modifications I 
>> would
>> have to make would be in setting the ranges, tailoring the SQL select
>> statement to match my data and maybe the Conn.Open statement.
>>
>> Would the ADO library be "Microsoft ADO Ext. 2.7 for DDL and Security"?
>> This is the only one I could find in my available references containing
>> "ADO".
>>
>> Thanks so much Tim!
>>
>> Rick
>>
>> "Tim Williams" wrote:
>>
>> > You might be able to adapt this to work for you.
>> > Need to add a reference to the ADO library to your VBA project.
>> >
>> > Tim
>> >
>> >
>> > '***********************************
>> > Sub TestJoin()
>> >
>> > Const S_TEMP_1 As String = "SQLtempTable1"
>> > Const S_TEMP_2 As String = "SQLtempTable2"
>> >
>> > Dim oConn As New ADODB.Connection
>> > Dim oRS As New ADODB.Recordset
>> > Dim sPath
>> >
>> > Dim rng1 As Range, rng2 As Range
>> >
>> >    Set rng1 = Sheet1.Range("A1:B6")
>> >    Set rng2 = Sheet2.Range("A1:B16")
>> >
>> >    Dim sSQL As String
>> >
>> >     sSQL = "select t1.ID, t1.COL1, t2.COL2 " & _
>> >            " from SQLtempTable1 t1, SQLtempTable2 t2 " & _
>> >            " where t1.ID = t2.ID"
>> >
>> >    'delete the range names and re-apply
>> >    On Error Resume Next
>> >    ThisWorkbook.Names.Item(S_TEMP_1).Delete
>> >    ActiveWorkbook.Names.Item(S_TEMP_2).Delete
>> >    On Error GoTo 0
>> >    ThisWorkbook.Names.Add Name:=S_TEMP_1, RefersToLocal:=rng1
>> >    ThisWorkbook.Names.Add Name:=S_TEMP_2, RefersToLocal:=rng2
>> >
>> >    sPath = ThisWorkbook.Path & "\" & ThisWorkbook.Name
>> >
>> >    oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
>> >               "Data Source=" & sPath & _
>> >               ";Extended Properties=""Excel 8.0;HDR=Yes"""
>> >
>> >    Set oRS = oConn.Execute(sSQL)
>> >
>> >    If Not oRS.EOF And Not oRS.BOF Then
>> >          Sheet3.Range("A2").CopyFromRecordset oRS
>> >    Else
>> >          MsgBox "No records found"
>> >    End If
>> >
>> > End Sub
>> > '***************************************
>> >
>> > "Gr8lyConfused" <Gr8lyConfused@discussions.microsoft.com> wrote in 
>> > message
>> > news:41EE2F52-6C6F-4520-8AD0-CB2282FC258E@microsoft.com...
>> > >
>> > > Is there a way to use pivot tables in Excel to accomplish the same 
>> > > result
>> > > as
>> > > an MS-Access process to "join" two tables on matching fields?    For
>> > > example,
>> > > I have one range of data that contains employee time card information 
>> > > that
>> > > includes a costing code for each time entry.   I have a separate data
>> > > range
>> > > that contains, for each costing code, one or more records containing
>> > > percentages that are used to allocate labor to specific business 
>> > > units.
>> > > The
>> > > desired result is a table or data range that contains all of the 
>> > > records
>> > > from
>> > > the time card range and all matching records from the allocation 
>> > > table.
>> > >
>> > > I've been able to build the result that I want using VBA code and 
>> > > vlookups
>> > > but I'm looking for a better way.  I've been researching Data
>> > > consolidations
>> > > and pivot tables with multiple ranges to see if this might work.  So 
>> > > far,
>> > > it
>> > > seems that these processes in Excel are simply to combining data 
>> > > rather
>> > > than
>> > > simulating a join.   Is there a way to do this with pivot tables or 
>> > > is
>> > > code
>> > > the only answer?
>> > >
>> > > Thanks in advance for any input!!!
>> >
>> >
>> > .
>> > 


0
Tim
4/10/2010 11:48:28 PM
Tim, I got this to work like I wanted on test data!   This is powerful, 
powerful stuff.  I experimented with various types of SQL statements to 
select and sum data ranges that I can use in other places in the application 
as well.   This certainly seems far superior to the VBA coding that I was 
doing that, at times, seemed like I was building the result one brick at a 
time.   Thanks again!!!!! 

"Tim Williams" wrote:

> "Microsoft ActiveX Data Objects 2.7 Library"
> 
> Earlier versions (eg. 2.5, 2.6) should also work.
> 
> Tim
> 
> 
> "Gr8lyConfused" <Gr8lyConfused@discussions.microsoft.com> wrote in message 
> news:A340C60C-8694-4753-BC2F-9A3F1ED7B1A5@microsoft.com...
> >
> > Ok, now I'm finding several ActiveX Data Object libraries.   The one that
> > looks like it has real promise is "ActiveX Data Objects Recordset 2.7
> > Library".
> >
> >
> > "Gr8lyConfused" wrote:
> >
> >> Thanks Tim!   This is great stuff.   It looks like the modifications I 
> >> would
> >> have to make would be in setting the ranges, tailoring the SQL select
> >> statement to match my data and maybe the Conn.Open statement.
> >>
> >> Would the ADO library be "Microsoft ADO Ext. 2.7 for DDL and Security"?
> >> This is the only one I could find in my available references containing
> >> "ADO".
> >>
> >> Thanks so much Tim!
> >>
> >> Rick
> >>
> >> "Tim Williams" wrote:
> >>
> >> > You might be able to adapt this to work for you.
> >> > Need to add a reference to the ADO library to your VBA project.
> >> >
> >> > Tim
> >> >
> >> >
> >> > '***********************************
> >> > Sub TestJoin()
> >> >
> >> > Const S_TEMP_1 As String = "SQLtempTable1"
> >> > Const S_TEMP_2 As String = "SQLtempTable2"
> >> >
> >> > Dim oConn As New ADODB.Connection
> >> > Dim oRS As New ADODB.Recordset
> >> > Dim sPath
> >> >
> >> > Dim rng1 As Range, rng2 As Range
> >> >
> >> >    Set rng1 = Sheet1.Range("A1:B6")
> >> >    Set rng2 = Sheet2.Range("A1:B16")
> >> >
> >> >    Dim sSQL As String
> >> >
> >> >     sSQL = "select t1.ID, t1.COL1, t2.COL2 " & _
> >> >            " from SQLtempTable1 t1, SQLtempTable2 t2 " & _
> >> >            " where t1.ID = t2.ID"
> >> >
> >> >    'delete the range names and re-apply
> >> >    On Error Resume Next
> >> >    ThisWorkbook.Names.Item(S_TEMP_1).Delete
> >> >    ActiveWorkbook.Names.Item(S_TEMP_2).Delete
> >> >    On Error GoTo 0
> >> >    ThisWorkbook.Names.Add Name:=S_TEMP_1, RefersToLocal:=rng1
> >> >    ThisWorkbook.Names.Add Name:=S_TEMP_2, RefersToLocal:=rng2
> >> >
> >> >    sPath = ThisWorkbook.Path & "\" & ThisWorkbook.Name
> >> >
> >> >    oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
> >> >               "Data Source=" & sPath & _
> >> >               ";Extended Properties=""Excel 8.0;HDR=Yes"""
> >> >
> >> >    Set oRS = oConn.Execute(sSQL)
> >> >
> >> >    If Not oRS.EOF And Not oRS.BOF Then
> >> >          Sheet3.Range("A2").CopyFromRecordset oRS
> >> >    Else
> >> >          MsgBox "No records found"
> >> >    End If
> >> >
> >> > End Sub
> >> > '***************************************
> >> >
> >> > "Gr8lyConfused" <Gr8lyConfused@discussions.microsoft.com> wrote in 
> >> > message
> >> > news:41EE2F52-6C6F-4520-8AD0-CB2282FC258E@microsoft.com...
> >> > >
> >> > > Is there a way to use pivot tables in Excel to accomplish the same 
> >> > > result
> >> > > as
> >> > > an MS-Access process to "join" two tables on matching fields?    For
> >> > > example,
> >> > > I have one range of data that contains employee time card information 
> >> > > that
> >> > > includes a costing code for each time entry.   I have a separate data
> >> > > range
> >> > > that contains, for each costing code, one or more records containing
> >> > > percentages that are used to allocate labor to specific business 
> >> > > units.
> >> > > The
> >> > > desired result is a table or data range that contains all of the 
> >> > > records
> >> > > from
> >> > > the time card range and all matching records from the allocation 
> >> > > table.
> >> > >
> >> > > I've been able to build the result that I want using VBA code and 
> >> > > vlookups
> >> > > but I'm looking for a better way.  I've been researching Data
> >> > > consolidations
> >> > > and pivot tables with multiple ranges to see if this might work.  So 
> >> > > far,
> >> > > it
> >> > > seems that these processes in Excel are simply to combining data 
> >> > > rather
> >> > > than
> >> > > simulating a join.   Is there a way to do this with pivot tables or 
> >> > > is
> >> > > code
> >> > > the only answer?
> >> > >
> >> > > Thanks in advance for any input!!!
> >> >
> >> >
> >> > .
> >> > 
> 
> 
> .
> 
0
Utf
4/11/2010 1:49:01 PM
Glad to hear it was useful.

Tim


"Gr8lyConfused" <Gr8lyConfused@discussions.microsoft.com> wrote in message 
news:0CDE9968-3DDD-4F69-B449-1C41E9A2F649@microsoft.com...
>
> Tim, I got this to work like I wanted on test data!   This is powerful,
> powerful stuff.  I experimented with various types of SQL statements to
> select and sum data ranges that I can use in other places in the 
> application
> as well.   This certainly seems far superior to the VBA coding that I was
> doing that, at times, seemed like I was building the result one brick at a
> time.   Thanks again!!!!!
>
> "Tim Williams" wrote:
>
>> "Microsoft ActiveX Data Objects 2.7 Library"
>>
>> Earlier versions (eg. 2.5, 2.6) should also work.
>>
>> Tim
>>


0
Tim
4/11/2010 11:31:49 PM
I'm using the SQL approach recommended above in a variety of ways to match, 
update and sum data in ranges.    While I'm close to getting the results I 
want, a problem has come up that I wasn't experincing prior to using ADO/SQL. 
  The problem is that, while testing the program, I often have to delete a 
few thousand records in my worksheet prior to testing a modified version of 
the program.   Deleting these records now takes an extraordinarily long time. 
  Sometimes an hour or longer.   So long that I've tried to use cntl-break to 
break out of the code to no avail.  After the records finally delete and I 
try my program again, Excel seems to be randomly recognizing cntl-breaks to 
stop execution of the VBA code when I haven't hit a cntl-break.   Re-starting 
Excel doesn't seem to help.   Re-starting Window (XP) does seem to get rid of 
the cntl-break problem but doesn't help with the time issue of deleting 
records.   One more piece of background information is that my VBA code is 
getting quite lengthy.  Since I'm re-working an existing program, I've copied 
all of the original subs from my old program into the new one so that any 
subs that I can reuse are readily available.    My questions are:

1) Are the problems that I'm experiencing more likely related to using ADO 
or the size of the program?

2) If the cause is likely using ADO, is there something that should be done 
to free or clean up memory after each use to keep from causing performance 
issues with deleting records?

Any help would be greatly appreciated.

Thanks in advance for your help. 

"Tim Williams" wrote:

> Glad to hear it was useful.
> 
> Tim
> 
> 
> "Gr8lyConfused" <Gr8lyConfused@discussions.microsoft.com> wrote in message 
> news:0CDE9968-3DDD-4F69-B449-1C41E9A2F649@microsoft.com...
> >
> > Tim, I got this to work like I wanted on test data!   This is powerful,
> > powerful stuff.  I experimented with various types of SQL statements to
> > select and sum data ranges that I can use in other places in the 
> > application
> > as well.   This certainly seems far superior to the VBA coding that I was
> > doing that, at times, seemed like I was building the result one brick at a
> > time.   Thanks again!!!!!
> >
> > "Tim Williams" wrote:
> >
> >> "Microsoft ActiveX Data Objects 2.7 Library"
> >>
> >> Earlier versions (eg. 2.5, 2.6) should also work.
> >>
> >> Tim
> >>
> 
> 
> .
> 
0
Utf
4/18/2010 3:32:01 PM
Hard to say exactly what's going on.  How are you deleting your records ?
Do you have any sheet-level event handlers which might be firing during the 
delete ?

If you're running the delete via code, try turning off Events and 
Calculation before doing the delete, then turn them back on after.

with Application
  .EnableEvents = False
  .Calculation = xlCalculationManual
  .Screenupdating = False
end with

'do deletes

with Application
  .EnableEvents = True
  .Calculation = xlCalculationAutomatic
  .Screenupdating = True
end with

If that doesn't work you'll need to provide some code.

If you'd like to mail me the workbook I will take a look.
timxxjxxwilliams (remove the x's) at gmail.com

Tim



"Gr8lyConfused" <Gr8lyConfused@discussions.microsoft.com> wrote in message 
news:C267A957-93D2-4FA0-B70A-8E7DED0E25E4@microsoft.com...
>
> I'm using the SQL approach recommended above in a variety of ways to 
> match,
> update and sum data in ranges.    While I'm close to getting the results I
> want, a problem has come up that I wasn't experincing prior to using 
> ADO/SQL.
>  The problem is that, while testing the program, I often have to delete a
> few thousand records in my worksheet prior to testing a modified version 
> of
> the program.   Deleting these records now takes an extraordinarily long 
> time.
>  Sometimes an hour or longer.   So long that I've tried to use cntl-break 
> to
> break out of the code to no avail.  After the records finally delete and I
> try my program again, Excel seems to be randomly recognizing cntl-breaks 
> to
> stop execution of the VBA code when I haven't hit a cntl-break. 
> Re-starting
> Excel doesn't seem to help.   Re-starting Window (XP) does seem to get rid 
> of
> the cntl-break problem but doesn't help with the time issue of deleting
> records.   One more piece of background information is that my VBA code is
> getting quite lengthy.  Since I'm re-working an existing program, I've 
> copied
> all of the original subs from my old program into the new one so that any
> subs that I can reuse are readily available.    My questions are:
>
> 1) Are the problems that I'm experiencing more likely related to using ADO
> or the size of the program?
>
> 2) If the cause is likely using ADO, is there something that should be 
> done
> to free or clean up memory after each use to keep from causing performance
> issues with deleting records?
>
> Any help would be greatly appreciated.
>
> Thanks in advance for your help.
>
> "Tim Williams" wrote:
>
>> Glad to hear it was useful.
>>
>> Tim
>>
>>
>> "Gr8lyConfused" <Gr8lyConfused@discussions.microsoft.com> wrote in 
>> message
>> news:0CDE9968-3DDD-4F69-B449-1C41E9A2F649@microsoft.com...
>> >
>> > Tim, I got this to work like I wanted on test data!   This is powerful,
>> > powerful stuff.  I experimented with various types of SQL statements to
>> > select and sum data ranges that I can use in other places in the
>> > application
>> > as well.   This certainly seems far superior to the VBA coding that I 
>> > was
>> > doing that, at times, seemed like I was building the result one brick 
>> > at a
>> > time.   Thanks again!!!!!
>> >
>> > "Tim Williams" wrote:
>> >
>> >> "Microsoft ActiveX Data Objects 2.7 Library"
>> >>
>> >> Earlier versions (eg. 2.5, 2.6) should also work.
>> >>
>> >> Tim
>> >>
>>
>>
>> .
>> 


0
Tim
4/18/2010 10:45:55 PM
Tim, I'm not aware of any sheet events that are programmed into my code.  
But, I think you're right that the cntl-break issue is related to that 
somehow.   One of the places that the code would break was on"Loop" statement 
after timer related DoWhile section looped around a DoEvents statement.  So, 
it has to be related to events.

I turned on manual calculation for the spreadsheet and the time required to 
delete records seem to have returned to normal for the time being anyway.   
If the problem shows up again I'll post some code.   Thank you for your help 
and expertise.

Rick


"Tim Williams" wrote:

> Hard to say exactly what's going on.  How are you deleting your records ?
> Do you have any sheet-level event handlers which might be firing during the 
> delete ?
> 
> If you're running the delete via code, try turning off Events and 
> Calculation before doing the delete, then turn them back on after.
> 
> with Application
>   .EnableEvents = False
>   .Calculation = xlCalculationManual
>   .Screenupdating = False
> end with
> 
> 'do deletes
> 
> with Application
>   .EnableEvents = True
>   .Calculation = xlCalculationAutomatic
>   .Screenupdating = True
> end with
> 
> If that doesn't work you'll need to provide some code.
> 
> If you'd like to mail me the workbook I will take a look.
> timxxjxxwilliams (remove the x's) at gmail.com
> 
> Tim
> 
> 
> 
> "Gr8lyConfused" <Gr8lyConfused@discussions.microsoft.com> wrote in message 
> news:C267A957-93D2-4FA0-B70A-8E7DED0E25E4@microsoft.com...
> >
> > I'm using the SQL approach recommended above in a variety of ways to 
> > match,
> > update and sum data in ranges.    While I'm close to getting the results I
> > want, a problem has come up that I wasn't experincing prior to using 
> > ADO/SQL.
> >  The problem is that, while testing the program, I often have to delete a
> > few thousand records in my worksheet prior to testing a modified version 
> > of
> > the program.   Deleting these records now takes an extraordinarily long 
> > time.
> >  Sometimes an hour or longer.   So long that I've tried to use cntl-break 
> > to
> > break out of the code to no avail.  After the records finally delete and I
> > try my program again, Excel seems to be randomly recognizing cntl-breaks 
> > to
> > stop execution of the VBA code when I haven't hit a cntl-break. 
> > Re-starting
> > Excel doesn't seem to help.   Re-starting Window (XP) does seem to get rid 
> > of
> > the cntl-break problem but doesn't help with the time issue of deleting
> > records.   One more piece of background information is that my VBA code is
> > getting quite lengthy.  Since I'm re-working an existing program, I've 
> > copied
> > all of the original subs from my old program into the new one so that any
> > subs that I can reuse are readily available.    My questions are:
> >
> > 1) Are the problems that I'm experiencing more likely related to using ADO
> > or the size of the program?
> >
> > 2) If the cause is likely using ADO, is there something that should be 
> > done
> > to free or clean up memory after each use to keep from causing performance
> > issues with deleting records?
> >
> > Any help would be greatly appreciated.
> >
> > Thanks in advance for your help.
> >
> > "Tim Williams" wrote:
> >
> >> Glad to hear it was useful.
> >>
> >> Tim
> >>
> >>
> >> "Gr8lyConfused" <Gr8lyConfused@discussions.microsoft.com> wrote in 
> >> message
> >> news:0CDE9968-3DDD-4F69-B449-1C41E9A2F649@microsoft.com...
> >> >
> >> > Tim, I got this to work like I wanted on test data!   This is powerful,
> >> > powerful stuff.  I experimented with various types of SQL statements to
> >> > select and sum data ranges that I can use in other places in the
> >> > application
> >> > as well.   This certainly seems far superior to the VBA coding that I 
> >> > was
> >> > doing that, at times, seemed like I was building the result one brick 
> >> > at a
> >> > time.   Thanks again!!!!!
> >> >
> >> > "Tim Williams" wrote:
> >> >
> >> >> "Microsoft ActiveX Data Objects 2.7 Library"
> >> >>
> >> >> Earlier versions (eg. 2.5, 2.6) should also work.
> >> >>
> >> >> Tim
> >> >>
> >>
> >>
> >> .
> >> 
> 
> 
> .
> 
0
Utf
4/19/2010 12:39:01 PM
Reply:

Similar Artilces:

Pivot Table Counting
I am having trouble trying to calculate fields through a pivot table. Basically, I have a data set that looks like this: Record Number State Value 1 CA 0 2 CA 12 3 CA 15 4 NJ 0 5 NJ 10 I want to set up a pivot table that will show 2 columns, one with th total number of records and one with the total number of records wit non-zero values. Both of the...

Pivot Tables #4
Hello you experts out there. I nned some Pivot table advice ( a website address for basics would be great), for instance how to excplain pivots and how to create them. I use lots of products with lots of sizes from various suppliers to name but a few columns. Is there a limit as to the amount of columns of data? Thank you very much. H Hi check out Debra Dalgleish's site - http://www.contextures.com/tiptech.html - she has a link to Jon Peltier's site which explains PT basics and then lots more interesting info on them. -- Cheers JulieD check out www.hcts.net.au/tipsandtric...

Pivot Chart Formatting #5
How can I format a Pivot Chart and keep the customized format when refreshed? This is a known issue by Microsoft. Short answer, you can't do it. =( One possible work around is to record a macro of you setting the formatting of the chart, and then set it up so that the macro runs whenever the chart calculates. -- Best Regards, Luke M *Remember to click "yes" if this post helped you!* "Germeny Santos" wrote: > How can I format a Pivot Chart and keep the customized format when refreshed? Hi, This is dependent on what custom formatting you are refering to. T...

Pivot table question: Sorting the subgroup in a pivot table (when using the top 10 option for the subgroup)
Hello: I have created a pivot table which has a one subgroup in the second column from the left. It uses the Top 10 option, so there are 10 subgroups So my data looks something like this: Group 1 50 Subgroup 1a 10 Subgroup 1b 40 Eight more subgroups Group 2 30 Subgroup 2a 20 Subgroup 2b 10 Eight more subgroups What I would like to do is sort by THe totals for Group 1, but then also sort by the subgroups, based on the values for each subgroup (similar to the "Sort by, ...

Help with pivot table
I'm after some help with a pivot table I have created a work book to log certain defects, and would like to use a pivot table to show defects per unit on an improvement tracker, is it possible to have the pivot table to shift cells to the right when it is updated and required more columns so it doesn't overwrite data on the sheet it would be like this the componet fault unit numbers & Total defects are the pivot table & the action would be the start of the manual data Compontent Fault Unit Numbers Total Defects Action 1 2 3 4 5 Light Inop 1 1 ...

Can I permanently delete/hide data within Pivot Tables?
Microsoft Excel 2002 I have 155 clients which I need to run Pivot Tables for! All with the same pivot table layout. Is it possible to run the Pivot table with the 155 clients as a Template basically, then somehow delete or permanently hide the data leaving only one client, so that I can save multiple copies for each of the individual clients? Or can I set up a pivot table where I can automatically feed in parameters? Client details are stored on an Oracle database! Hi Peter, Right-click on a Page Field and select Field Settings from the context menu, then click the Advanced button. Yo...

In Excel, how can a range of Pos #'s be changed to negative num
I dulicate a large series of cells that are all positive. Is there a shortcut to change them to all negaive? Hi, Type -1 in a cell, copy that and then select the range, which has the positive numbers which you want to convert to negative. Right click on the range, select paste special, and choose action as 'Muliply'. Regards Govind. Stuart Millner wrote: > I dulicate a large series of cells that are all positive. Is there a > shortcut to change them to all negaive? Perfect, thanks a million, what an easy solution.... "Govind" wrote: > Hi, > > ...

Possible to chart data for dates implicit within a range?
I have a list of computer programs with start and end dates for each. I need to determine how many programs were running on my system on any given day. Can I get this data for individual days between the start and end dates without creating columns for each intermediate day? Ex.: Program 1 ran from 01/01/2005 to 01/14/2005. Program 2 ran from 01/06/2005 to 01/22/2005. Is it possible to chart the total number of programs running on 01/08/2005 without manually creating a column for that date? Thanks, Nechama You can compute this with formulas. Star with data in A1:C4 as follows: ...

Using formulas for pivot table
I know you have the count field but is there away to input a formula? For example customer ordered 25 cases and each case weighs 4 lbs and the end result would need to be total pounds ordered. Thanks! If you do the calculation in the pivot table you may not get the result that you expect. If possible, add a field to the source data, and calculate the order total there. Then, add the OrderTotal field to the pivot table's data area. tskb wrote: > I know you have the count field but is there away to input a formula? > For example customer ordered 25 cases and each case weighs 4 lbs...

Hyperlink in Pivot Table
Is it possible to put hyperlinks into a pivot table to go to the detail in other worksheets? I have a top 10 list of components with issues and would like the user to be able to click on the component to go to the list of issues. I thought if I put the hyperlink in the cell where the pivot table is getting it's info, it would come through, but that didn't work. Any suggestions? Thanks Hi Just double clicking on the cell with the data of interest, will open another sheet showing all of the entries making up that value. Delete the newly created sheet after you have finished w...

Flowcharting Table relations
Hey guys and girls. New one for you. I am doing an IT audit of Great Plains and need to flowchart how the data files are related to each other. In other words, how does one file feed into another file, and what field or fields in a particular table is used to relate/link to another table. Does anyone where I can find such information? Thanks Check out the Great Plains SDK available on the installation CDs. There are several diagrams that describe table relationships. Also, there are module documents that contain posting flowcharts. Regards, Kevin Rood Corporate Software Consultants...

chart options show data table
Currently using 2 workbooks to produce 1 chart - the source data in workbook 1 and the chart in workbook 2. We also are using the "show data table" option to most easily view all values in the chart. We would like this data to keep it's currency format to best reflect the values in the chart; however, the data table loses this formatting when we close workbook 1. Is there any way to hang onto this formatting after the workbook is closed? Data tables in charts are not particularly flexible or capable. You combine the workbooks. Alternatively, put a table in the chart's...

Pivot Tables #40
Does anyone know if there is a way to quickly clear a field list? I can't find a keyboard shortcut or anything else in any of the help/support avenues I've tried. Thanks in advance for the help. -- ERR229 Are you trying to clear all the check boxes in the field's dropdown list? In Excel 2002 and later versions, there's a Show All checkbox. In Excel 2000, and earlier versions, you can use programming to hide or show the items -- there's sample code here: http://www.contextures.com/xlPivot03.html ERR229 wrote: > Does anyone know if there is a way to quickl...

line column Pivot Charts
Access 2003 does not support combined Line/Column Charts, but Excel does. Has the capability been added to Access 2007? Access does support a series displayed as a bars and another series as line. -- Duane Hookom MS Access MVP Help me support UCP http://www.access.hookom.net/UCP/Default.htm "John" <John@discussions.microsoft.com> wrote in message news:A0DD25F6-D99A-44C3-812B-416776BED8AF@microsoft.com... > Access 2003 does not support combined Line/Column Charts, but Excel does. > Has > the capability been added to Access 2007? ...

I need to convert a word table to excel
When I try doing this by copying the table it appears in excelwith one or two empty lines in between each of my lines that I needed converting. Why is this? usually means there are superfluous paragraph marks in the Word table. "Aaron" <Aaron@discussions.microsoft.com> wrote in message news:012E3413-1F64-4018-BC14-A2D6AB68B668@microsoft.com... > When I try doing this by copying the table it appears in excelwith one or > two > empty lines in between each of my lines that I needed converting. Why is > this? ...

deactivate the get pivot formula when I link a cell to a pivot
Currently I using excel 2003, but every time when I link the cell to a pivot table it will convert to a "Get pivot" formula. Is there any way I could deactivate it? See Debra Dalgleish's website for instructions: http://www.contextures.com/xlPivot06.html Does that help? *********** Regards, Ron XL2002, WinXP-Pro "hwtradezheng" wrote: > Currently I using excel 2003, but every time when I link the cell to a pivot > table it will convert to a "Get pivot" formula. Is there any way I could > deactivate it? ...

pivot table error (25000 rows!!)
I am trying to run a pivot table on a file containing 25000 rows. I have 5 duplicate (identical structure) files. The pivot works on each but one. On this file I get an error saying it has too many columns or rows in the pivot table. Drag at least one column or row off the table... Does anybody know what the reason for this message is, are their limits to rows or columns? The identical table works on the other files, therefore this message is so strange. Who has an idea? -- Craig_Richards ------------------------------------------------------------------------ Craig_Richards's Profil...

Pivot table move up command
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) I need to move up values in a pivot table to custom order them. When I right-click I see the &quot;Move&quot; menu, but the options to move up, move down, move to beginning and move to end are greyed out. Did you find an answer? Katy MelKC wrote: Pivot table move up command 04-Feb-10 Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) I need to move up values in a pivot table to custom order them. When I right-click I see the &quot;Move&quot; menu, but the options to move up, move d...

enterprise resources in which table of which database
when i add resource from active directory to resource center .and i want to know in which database and in which table it will saved first. -- It should be in the Published and the Reporting database. In the tables labeled "..Resource" Jonathan "Basim" <Basim@discussions.microsoft.com> wrote in message news:B443F9A1-E8FD-4DF5-A347-A13A626EDE67@microsoft.com... > when i add resource from active directory to resource center .and i want > to > know in which database and in which table it will saved first. > > > -- > ...

Opening a window(form) with VBA / storing data in a separate table
Hi all, First Question---- I have a third party application (Additional Inventory Fields in the ActNow series from Hawk Mountain) that currently is accessed from the Extra menu while in item maintenance. I have added a button to the item maintenance form and I am trying to figure our what VBA code I need to put in so that when the user clicks on the button that it launches the form that is currently accessed via the menu. This is not currently a VBA form but the window that comes with the application. I have tried to put an "OnUserChanged" event on the button with a FormName.Open...

Auto filter and Pivot Table
Is it possible to auto filter data, and use it as input to a Pivot table? When I run a test where I first auto filter, I initially had 20000 rows, and the auto filter reduced it to 12000 rows. But when I go to crearte a pivot table on the filtered data, I am back to a total record count of 20000. Am I combining apples and oranges? If so, is there a way to filter data, before it gets inputed to a Pivot table? -- RandyLewisKemp ------------------------------------------------------------------------ RandyLewisKemp's Profile: http://www.excelforum.com/member.php?action=getinfo&use...

Strange Icon
I have noticed a strange picture/icon (Can't paste it here) A small icon with a Blue J and a yellow background. I can identify it or it's purpose. Anyone know what it is? What it does? Thank and Seasons Greeting! What version of Excel are you using? Where/when does the icon appear? HW wrote: > I have noticed a strange picture/icon (Can't paste it here) A small icon > with a Blue J and a yellow background. I can identify it or it's purpose. > > Anyone know what it is? What it does? > > Thank and Seasons Greeting! -- Debra...

Pivot Table Update?
I have an existing pivot table that works OK - but I want it to recognise and automatically update when a new line of data is input - how can I do this? -- ajames ------------------------------------------------------------------------ ajames's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=31502 View this thread: http://www.excelforum.com/showthread.php?threadid=514328 Use a dynamic range name--one that grows and contracts with your data. See Debra Dalgeish's site for some nice tips: http://contextures.com/xlNames01.html#Dynamic Then all you'll hav...

Unwanted arrows when "Format As Table"
When I select my Excel 2007 worksheet and format it as a preset table style, the first row always contains dropdown arrows that are totally unneeded for my styling. How can I get rid of those arrows? Thanks. >When I select my Excel 2007 worksheet and format it as a preset table >style, the first row always contains dropdown arrows that are totally >unneeded for my styling. How can I get rid of those arrows? Thanks. Here is a before/after pic to show what a distraction the header arrows are. http://img178.imageshack.us/img178/8017/excelba2.jpg Now I understand what the issue is....

Pivot Charts #4
Is there a way to change the pivot chart without changing the table in the process? ...