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

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
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,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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