Excel - Problems exporting to Excel - selecting correct sheet
Asked By M Skabialka
02-Feb-10 03:14 PM
I am using some code from Ken Snell to export data from Access to an Excel
spreadsheet which is set up already with formatting and formulas.
When I use this code:
Set xls = xlw.Worksheets("005")
the information goes to the correct spreadsheet.
But when I use this code
Set xls = xlw.Worksheets(rst!LineNumber) ' where rst!LineNumber =
Set xlc = xls.Range("a5") ' this is the first cell into which data go
For lngColumn = 0 To rst.Fields.Count - 1
xlc.Offset(0, lngColumn).value = rst.Fields(lngColumn).value
Next lngColumn
The info for spreadsheet "005" goes into sheet number "004", and all of the
info goes into the previously numbered sheet.
There are 100 sequentially numbered sheets.
I have stepped through the code and cannot tell why it is choosing the wrong
sheet - any ideas?
Mich
Worksheets
(1)
Excel
(1)
LineNumber
(1)
Snellhttp
(1)
LngColumn
(1)
Mich
(1)
Xlc
(1)
M Skabialka replied to M Skabialka
Answering my own question - this works but I do not know why:
Set xls = xlw.Worksheets(Format(Val(rst!LineNumber), "000"))
Mich
Dave Peterson replied to M Skabialka
I do not speak the access, but maybe:
Set xls = xlw.Worksheets(format(rst!LineNumber, "000"))
There is a difference between:
xlw.worksheets("005")
and
xlw.worksheets(5)
The first is using the name of the worksheet. The second is using the 5th
worksheet (counting from the left hand side).
--
Dave Peterson
Ken Snell replied to Dave Peterson
Yes, I concur with Dave's analysis of the situation.
--
Ken Snell
http://www.accessmvp.com/KDSnell/
Win7 VirtualStore Weirdness with Excel 2002 and earlier Excel I thought I'd share a weird experience I had today in case it saves installer for it - - which registers it as an add-in for all installed versions of Excel - - and tested it. Fine in Windows 2000 in all installed versions of Excel. Boot to Windows XP, fine there too. Boot to Windows 7. Fine in Excel 2010, 2007, and 2003. But Excel 2002 and 2000 were still loading the old version of the add-in. I uninstalled the add-in, made sure it was gone, and reinstalled it. Same problem in Excel 2002 and earlier; still works fine in Excel 2003 and later. I opened the VB editor in Excel 2003 and in Excel 2002
32 bit DLL with 64 bit Excel 2010 Excel We have an app which creates large Excel workbooks. For example, one workbook has 1, 000 worksheets. In other cases there are fewer worksheets but the Excel file can be 80 MB or larger. Since this sometimes crashes Excel 2007 and 2003, I am considering using 64 bit Excel 2010. Would 64-bit Excel be more reliable with workbooks this size than 32-bit
how to find union of two arrays Excel Hello, Does anyone know a means of comparing two very large arrays (> 50000 elements) to to both arrays? I have tried using looping functions and that is far too slow. Excel Programming Discussions GetCurrentProcessId (1) Worksheets (1) Excel 2003 (1) Excel 2007 (1) Workbooks (1) Excel (1) Statistics (1) Relative (1) hi, i do not know why your looping is far to 50000 dataX = 3Dworksheets(1).cells(k1, 1) For k2 = 3D1 to 50000 dataY = 3D worksheets(2).cells(k2, 1) If dataX = 3DdataY then worksheets(1).cells(k1, 2) = 3Dworksheets(2).cells(k2, 2) end if next next This code
Another 'Copy To The Next Available Row' Question Excel I have an Excel 2007 spread sheet where I enter information on one sheet, and the ???data??? is stored Sub SaveMyData() ' ' SaveData Macro ' Saves information from Dashboard to Data ' Dim lastrow As Long lastrow = Worksheets("Data").Range("O1048576").End(xlUp).Row nextRow = lastrow + 1 Source_Date = "D6" ' date Source_State = "H6" ' state two ' two comment blocks due to 255 character per cell limit InputRange = Source_Date NextCol = Destination_Date Worksheets("Dashboard").Range(Source_Date).Copy Destination: = Worksheets("Data").Range(NextCol & nextRow) Worksheets("Dashboard").Range(Source_Date).ClearContents InputRange = Source_State NextCol = Destination_State Worksheets("Dashboard").Range(Source_State).Copy Destination: = Worksheets("Data").Range(NextCol & nextRow) Worksheets("Dashboard").Range(Source_State).ClearContents InputRange = Source_Inquiry_Type NextCol = Destination_Inquiry_Type Worksheets("Dashboard
How to create a shared procedure Excel My workbook has 3 very hidden master worksheets, named PANEL, DIST and LOADS. This workbook is designed for electrical wiring calculation. The user Then If Target.Offset(0, 1) = 3D "X" Then If SheetExists(whereto) = 3D "True" Then Worksheets(whereto).Range("Transformer") = 3D CurrSht Worksheets(whereto).Range("sourceXfmrKVA") = 3D Target.Offset(-1, 0) Worksheets(CurrSht).Select 'return to original sheet If Worksheets(whereto).Range("zID") = 3D "PANEL" Then If Worksheets(whereto).Range("ConfigNum") = 3D 7 Or Worksheets(whereto).Range("ConfigNum") = 3D 8 Then If Target.Offset(-1, 32) = 3D 3 Or Target