J
J.W. Aldridge
Normally, my code works fine if I have a few rows of data. However,
I've found that if there's only information in the first two rows (a-
f), I get an error (Run Time: AutoFill Method of range class failed).
Any way to get the code to fill down to row 2 and stop if there's no
more info and not give me an error?
This is the fill down code. The part that returns the error is the
line 7 - 9.
***********************
Range("F2").Select
ActiveCell.FormulaR1C1 = "Next day"
Range("F2").Select
With ThisWorkbook.Worksheets("2mindex")
Set rngData = .Range("e2:e" & .Cells(.Rows.Count, "e").End
(xlUp).Row)
Set rngFormula = .Range("f2")
rngFormula.AutoFill _
Destination:=.Range(rngFormula, _
.Cells(rngData.Rows(rngData.Rows.Count).Row,
rngFormula.Column))
End With
************************
Here's the entire code just in case....
Sub rearrange_data()
..
Columns("B:B").Select
Application.CutCopyMode = False
Selection.Insert Shift:=xlToRight
Columns("F:F").Select
Selection.Cut Destination:=Columns("B:B")
Columns("B:B").Select
ActiveWindow.SmallScroll ToRight:=0
Columns("G:L").Select
Selection.Delete Shift:=xlToLeft
Range("F1").Select
ActiveCell.FormulaR1C1 = "Reason"
Range("F2").Select
ActiveCell.FormulaR1C1 = "Next day"
Range("F2").Select
With ThisWorkbook.Worksheets("2mindex")
Set rngData = .Range("e2:e" & .Cells(.Rows.Count, "e").End
(xlUp).Row)
Set rngFormula = .Range("f2")
rngFormula.AutoFill _
Destination:=.Range(rngFormula, _
.Cells(rngData.Rows(rngData.Rows.Count).Row,
rngFormula.Column))
End With
Columns("A:F").Select
Selection.Sort Key1:=Range("C2"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub
I've found that if there's only information in the first two rows (a-
f), I get an error (Run Time: AutoFill Method of range class failed).
Any way to get the code to fill down to row 2 and stop if there's no
more info and not give me an error?
This is the fill down code. The part that returns the error is the
line 7 - 9.
***********************
Range("F2").Select
ActiveCell.FormulaR1C1 = "Next day"
Range("F2").Select
With ThisWorkbook.Worksheets("2mindex")
Set rngData = .Range("e2:e" & .Cells(.Rows.Count, "e").End
(xlUp).Row)
Set rngFormula = .Range("f2")
rngFormula.AutoFill _
Destination:=.Range(rngFormula, _
.Cells(rngData.Rows(rngData.Rows.Count).Row,
rngFormula.Column))
End With
************************
Here's the entire code just in case....
Sub rearrange_data()
..
Columns("B:B").Select
Application.CutCopyMode = False
Selection.Insert Shift:=xlToRight
Columns("F:F").Select
Selection.Cut Destination:=Columns("B:B")
Columns("B:B").Select
ActiveWindow.SmallScroll ToRight:=0
Columns("G:L").Select
Selection.Delete Shift:=xlToLeft
Range("F1").Select
ActiveCell.FormulaR1C1 = "Reason"
Range("F2").Select
ActiveCell.FormulaR1C1 = "Next day"
Range("F2").Select
With ThisWorkbook.Worksheets("2mindex")
Set rngData = .Range("e2:e" & .Cells(.Rows.Count, "e").End
(xlUp).Row)
Set rngFormula = .Range("f2")
rngFormula.AutoFill _
Destination:=.Range(rngFormula, _
.Cells(rngData.Rows(rngData.Rows.Count).Row,
rngFormula.Column))
End With
Columns("A:F").Select
Selection.Sort Key1:=Range("C2"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub