Hej.
Jeg har kreeret en fil indeholdende 2 ark hvor jeg på det ene ark importere externe data, og på det andet ark har en kap til at importere de externedata ved en makro.
Jeg har samtidig på samme side en knap til at 0-stille formularen og som sletter de importerede data i det første ark.
Det virker såmend rigtig godt bare jeg først importere data og derefter 0-stiller ark, men kommer jeg til at klikke på importer data knappen 2 gange efter hinanden, f.eks. hvis jeg har en rettelse i den externe datafil,/uploads/182/052.zip" rel="nofollow">uploads/182/052.zip ja så flytter alle kollonnerne sig og jeg kan ikke 0-stille herefter og får fejl.
Er der nogen der kan hjælpe mig med at finde vej til at jeg kan
Jeg oploader selve filen og makro koderne er her for:
Import af data:
Sub sorter052() ' ' sorter052 Makro ' Makro indspillet 24-09-2011 af Stig Petersen '
' Sheets("0").Select Range("A1").Select ActiveSheet.Unprotect "'" With ActiveSheet.QueryTables.Add(Connection:= _ "TEXT;C:\SPtaxi\nordvagt\vagt-filer\052.csv", Destination:=Range("A1")) .Name = "052" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .TextFilePromptOnRefresh = False .TextFilePlatform = 850 .TextFileStartRow = 1 .TextFileParseType = xlDelimited .TextFileTextQualifier = xlTextQualifierDoubleQuote .TextFileConsecutiveDelimiter = False .TextFileTabDelimiter = False .TextFileSemicolonDelimiter = False .TextFileCommaDelimiter = True .TextFileSpaceDelimiter = False .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _ 1, 1, 1, 1, 1) .TextFileTrailingMinusNumbers = True .Refresh BackgroundQuery:=False End With Range("A1:Z105").Select Selection.Sort Key1:=Range("B1"), Order1:=xlAscending, Key2:=Range("D1") _ , Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _ False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _ :=xlSortNormal Range("A1").Select ActiveSheet.Protect Password:="'", DrawingObjects:=True, Contents:=True, Scenarios:=True Sheets("c052").Select ActiveWindow.SmallScroll Down:=129 Range("A1").Select ActiveSheet.Protect Password:="'", DrawingObjects:=True, Contents:=True, Scenarios:=True ActiveWorkbook.Save End Sub
0-stil:
Sub Reset052() ' ' Reset052 Makro ' Makro indspillet 27-09-2011 af Stig Petersen '
' Sheets("0").Select Range("A1:Z105").Select ActiveSheet.Unprotect "'" Selection.ClearContents Selection.QueryTable.Delete ActiveWindow.SmallScroll Down:=-12 Range("A1").Select ActiveSheet.Protect Password:="'", DrawingObjects:=True, Contents:=True, Scenarios:=True Sheets("c052").Select Range("G19").Select ActiveCell.FormulaR1C1 = "0" Range("G20").Select ActiveCell.FormulaR1C1 = "0" Range("G21").Select ActiveCell.FormulaR1C1 = "0" Range("G22").Select ActiveCell.FormulaR1C1 = "0" Range("G41").Select ActiveCell.FormulaR1C1 = "0" Range("G42").Select ActiveCell.FormulaR1C1 = "0" Range("G43").Select ActiveCell.FormulaR1C1 = "0" Range("G44").Select ActiveCell.FormulaR1C1 = "0" Range("G63").Select ActiveCell.FormulaR1C1 = "0" Range("G64").Select ActiveCell.FormulaR1C1 = "0" Range("G65").Select ActiveCell.FormulaR1C1 = "0" Range("G66").Select ActiveCell.FormulaR1C1 = "0" Range("G85").Select ActiveCell.FormulaR1C1 = "0" Range("G86").Select ActiveCell.FormulaR1C1 = "0" Range("G87").Select ActiveCell.FormulaR1C1 = "0" Range("G88").Select ActiveCell.FormulaR1C1 = "0" Range("G107").Select ActiveCell.FormulaR1C1 = "0" Range("G108").Select ActiveCell.FormulaR1C1 = "0" Range("G109").Select ActiveCell.FormulaR1C1 = "0" Range("G110").Select ActiveCell.FormulaR1C1 = "0" Range("G129").Select ActiveCell.FormulaR1C1 = "0" Range("G130").Select ActiveCell.FormulaR1C1 = "0" Range("G131").Select ActiveCell.FormulaR1C1 = "0" Range("G132").Select ActiveCell.FormulaR1C1 = "0" Range("G151").Select ActiveCell.FormulaR1C1 = "0" Range("G152").Select ActiveCell.FormulaR1C1 = "0" Range("G153").Select ActiveCell.FormulaR1C1 = "0" Range("G154").Select ActiveCell.FormulaR1C1 = "0" Range("G173").Select ActiveCell.FormulaR1C1 = "0" Range("G174").Select ActiveCell.FormulaR1C1 = "0" Range("G175").Select ActiveCell.FormulaR1C1 = "0" Range("G176").Select ActiveCell.FormulaR1C1 = "0" Range("G195").Select ActiveCell.FormulaR1C1 = "0" Range("G196").Select ActiveCell.FormulaR1C1 = "0" Range("G197").Select ActiveCell.FormulaR1C1 = "0" Range("G198").Select ActiveCell.FormulaR1C1 = "0" Range("G217").Select ActiveCell.FormulaR1C1 = "0" Range("G218").Select ActiveCell.FormulaR1C1 = "0" Range("G219").Select ActiveCell.FormulaR1C1 = "0" Range("G220").Select ActiveCell.FormulaR1C1 = "0" Range("A1:L1").Select ActiveSheet.Protect Password:="'", DrawingObjects:=True, Contents:=True, Scenarios:=True ActiveWorkbook.Save End Sub
|