Hi All,
The code below works fine on a machine running Excel 2003 but when transferred to a machine running Vista with Excel 2007 I get a “Run time Error 1004”
Is there a way to have the same code run on both versions?
PS I have deliberately done all my development in 2003 believing that it would all work on 2007 but that it would not work the other way around. Am I correct?
Regards,
Alan
FinalRow = Cells(Rows.count, 1).End(xlUp).Row Range("A2:Z" & FinalRow).Select Selection.Sort Key1:=Range("T2"), Order1:=xlAscending, Key2:=Range("S2") _ , Order2:=xlAscending, Key3:=Range("V2"), Order3:=xlAscending, Header:= _ xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _ xlSortNormal
Last edited by AlanAnderson; 07-20-2010 at 05:49 AM.
Your code works fine for me in 2007. My guess is it's something outside of the code you've provided which is causing the problem.
Can you upload the workbook?
Dion
Hi Dion,
Thanks for the help.
I think you are right. It is probably not feasible to upload the entire workbook as it is really big.
What I have noticed is that 2007 is creating a fancy table with headers containing sorting facilities etc. This does not occur in 2003. Seeing as the error message refers to a sort problem is this not the issue?
What can I put in the code to either "switch off" this facility in 2007 or to make the 2003 sort "acceptable" to the new type of table?
Thanks again,
Alan
What exactly is this range you are sorting? An external query?
Have you tried including row 1 in the sort and specifying that you have headers?
Try using the macro Recorder whilst sorting, then post the code for help modifying it
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel Tips & Solutions, free examples and tutorials why not check out my downloads
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
FWIW, I just tested your code on a simple table in 2007 and it worked fine, so maybe a sample of the actual failing workbook would be useful.
Hi,
I am in the process of extracting the offending modules and sheets from the programme.
Will get back later
Hi Again,
I am enclosing the module that contains the "offending" code.
I am also enclosing 4 xls files.
Whilst being a total newbiw I am convinced the problem lies in these. . Where the import file and export files are both handled in Excel 2003 the info resides in a straight forward data format..
When these files are taken to a 2007 machine a table is created with facilities for sorting etc which does not happen in 2003.
btw the format of some of the columns also changes (num,bers to dates etc) but this may just be a bug I have not looked into yet.
What really bugs me is that this code works perfectly in 2003 - its just when copied to 2007 it falls over.
Please help - I really am lost.
Regards,
Alan.
PS the entire programme is very large.and cant be uploaded.
This code opens the file and imports it into my data file to a page called PasConv
After the above code is all run then following routine sorts and then puts data ito various pages. The web page will not allow the entire routine as its too large so I have cut it off just after the problem occurs.Sub ImportPastelXls() Application.ScreenUpdating = False Application.Calculation = xlCalculationManual Sheets("PasConv").Select FinalRow = Cells(Rows.count, 1).End(xlUp).Row Range("a1", "ag" & FinalRow).Select Selection.ClearContents Dim FileName As Variant Dim FInfo As String Dim FIndex As Integer Dim Title As String FInfo = "XL Worksheets Files (*.xls),*.xls," & "All files (*.*),*.*," FIndex = 1 Title = "Choose the file you wish to import" FileName = Application.GetOpenFilename(FInfo, FIndex, Title) If FileName = False Then MsgBox "Please select a valid existing data file" Exit Sub End If Debug.Print "Filename: " & FileName; "" ImportXLFilePastel fname:=CStr(FileName) Application.ScreenUpdating = True Application.Calculation = xlCalculationAutomatic End Sub Public Sub ImportXLFilePastel(fname As String) Application.Calculation = xlCalculationManual Application.ScreenUpdating = False Dim FinalRowFr As Long Dim WriteRow As Long Dim FullName As String Dim nFileName As String FullName = fname nFileName = GetFileName(FullName) Application.Workbooks.Open (FullName) Sheets(1).Select FinalRowFr = Cells(Rows.count, 9).End(xlUp).Row FinalRowFr = FinalRowFr + 1 ActiveWindow.WindowState = xlMaximized FinalRow = Cells(Rows.count, 9).End(xlUp).Row WriteRow = FinalRow + 1 FinalCol = Cells(3, Columns.count).End(xlToLeft).Column Range("A1", "ag" & FinalRowFr).Select Selection.Copy ActiveWindow.WindowState = xlMinimized Sheets("PasConv").Select ' Range("a1", "Q" & FinalRow).Select ' MsgBox (FinalRow) ' Selection.ClearContents Range("A1").Select ActiveSheet.Paste Selection.Columns.AutoFit Application.CutCopyMode = False With Selection.Font .Name = "Arial" .FontStyle = "Regular" .Size = 8 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = xlAutomatic End With Call SelectSageCols Call FixDateSage Call TaxTable Call SagePgNames Call CalcTotals Call TransferSagePages Application.ScreenUpdating = True Sheets("Menu").Select frmVarMenu.Show Application.Calculation = xlCalculationAutomatic zz: End Sub
Sub TransferSagePages() Dim currRow As Long Dim CurrCol As Integer Dim VatCol As Integer Dim SrcTypeCol As Integer Dim TranCol As Integer Dim CustCol As Integer Dim DateCol As Integer Dim VatRateCol As Integer Dim VatAmtCol As Integer Dim NetAmtCol As Integer Dim TotIncVatCol As Integer Sheets("PasConv").Select FinalRow = Cells(Rows.count, 1).End(xlUp).Row FinalCol = Cells(1, Columns.count).End(xlToLeft).Column Range("A1:Z" & FinalRow).Select Application.CutCopyMode = False Selection.Sort Key1:=Range("T2"), Order1:=xlAscending, Key2:=Range("S2") _ , Order2:=xlAscending, Key3:=Range("V2"), Order3:=xlAscending, Header:= _ xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _ xlSortNormal 'Range("A1:Y109").Select 'Application.CutCopyMode = False 'Selection.Sort Key1:=Range("T2"), Order1:=xlAscending, Key2:=Range("S2") _ , Order2:=xlAscending, Key3:=Range("V2"), Order3:=xlAscending, Header:= _ xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _ xlSortNormal Cells(1, 18) = "Tot_Incl_VAT" Columns("R:V").Select
Sorry,
Having real problems uploading files.
If I could just describe the data files.
They are simple - just 10columns containining data. 3 columns containing data obtained by simple arithmetic calculations based on other columns.
All columns have headers.
WWhere the files are in 2007 those headers get changed to "smart headers" - ie you can click on headers to sort data. This is not the case in 2003.
When I try to use VBA generated in 2003 to sort these "converted files" it falls over.
Regards,
Alan
Hi,
Problem solved. I had to write routine that did different sort depending on version.
Thanks,
Alan
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks