How am I complicating this?

crazybuckeyeguy

New Member
Joined
Apr 15, 2017
Messages
49
just a simple copy and paste. add formula and fill down then copy, past and sort. What am I missing?

Sub Macro4()
'
' Macro4 Macro
Dim i As Long
Application.ScreenUpdating = False
i = Range("A" & Rows.Count).End(xlUp).Row
For i = lr To 2 Step -1
Range("n12:n" & i).Copy Range("E12:E" & i)
Range("O12").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=TIMEVALUE(RC[-1])"
Range("o12:o" & i).FillDown
Range("O12:O" & i).Select
Selection.Copy
Range("E12").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Columns("E:E").Select
Application.CutCopyMode = False
Selection.NumberFormat = "[$-en-US]h:mm AM/PM;@"
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("E12:E" & i _
), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("A11:Q" & i)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Next I
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
so whats happening with the code ?
 
Upvote 0
i = Range("A" & Rows.Count).End(xlUp).Row
For i = lr To 2 Step -1

You have not yet set a value to lr
I think that should be

lr = Range("A" & Rows.Count).End(xlUp).Row
For i = lr To 2 Step -1
 
Upvote 0
i = Range("A" & Rows.Count).End(xlUp).Row
For i = lr To 2 Step -1

You have not yet set a value to lr
I think that should be

lr = Range("A" & Rows.Count).End(xlUp).Row
For i = lr To 2 Step -1
OK now my formula isn't copying and filling down to the last row. any ideas?
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,260
Members
452,627
Latest member
KitkatToby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top