Aanee Posted August 25, 2015 Share Posted August 25, 2015 Hej Har spelat in ett makro som fungerar som jag vill ha det men när jag ska köra makrot igen får jag detta felmeddelande och det är alltså AutoFill som strular. Jag skulle egentligen vilja att formeln fylls i till sista raden eftersom det kan vara olika antal rader beroende på vilken data man kör makrot på. Har ni några tips? Sub Makro1() ' ' Makro1 Makro ' ' ActiveCell.FormulaR1C1 = "=IF(RC[-10]=""Z1"",RC[-8]-1,RC[-8])" Selection.AutoFill Destination:=Range("L2:L227"), Type:=xlFillDefault Range("L2:L227").Select Selection.NumberFormat = "m/d/yyyy" Columns("A:L").Select Selection.Subtotal GroupBy:=12, Function:=xlSum, TotalList:=Array(6), _ Replace:=True, PageBreaks:=False, SummaryBelowData:=True ActiveSheet.Outline.ShowLevels RowLevels:=2 End Sub Link to comment Share on other sites More sharing options...
Monshi Posted August 25, 2015 Share Posted August 25, 2015 pröva Sub Makro1() ' ' Makro1 Makro ' ' Dim myRn As Variant On Error Resume Next Set myRn = Application.InputBox("Välj startcell", "Fyll&Kopiera", Type:=8) On Error GoTo 0 If myRn Is Nothing Then Exit Sub Dim rnLastcell As Integer rnLastcell = myRn.Offset(0, -1).End(xlDown).Offset(0, 1).Row + 1 myRn.Resize(rnLastcell - myRn.Row).FormulaR1C1 = "=IF(RC[-10]=""Z1"",RC[-8]-1,RC[-8])" myRn.Resize(rnLastcell - myRn.Row).NumberFormat = "m/d/yyyy" myRn.CurrentRegion.Subtotal GroupBy:=12, Function:=xlSum, TotalList:=Array(6), _ Replace:=True, PageBreaks:=False, SummaryBelowData:=True ActiveSheet.Outline.ShowLevels RowLevels:=2 End Sub Link to comment Share on other sites More sharing options...
Aanee Posted August 25, 2015 Author Share Posted August 25, 2015 Perfekt, funkar fint! Skulle dock vilja att formeln alltid börjar i L2 utan en ruta som frågar efter startcell, hur gör man då? Link to comment Share on other sites More sharing options...
Monshi Posted August 25, 2015 Share Posted August 25, 2015 Ändra raden Set myRn = Application.InputBox("Välj startcell", "Fyll&Kopiera", Type:=8) till Set myRn = Range("L2") Link to comment Share on other sites More sharing options...
Aanee Posted August 25, 2015 Author Share Posted August 25, 2015 Strålande, tack för hjälpen! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.