Autofill down to last used row not working

rfletcher35

Active Member
Joined
Jul 20, 2011
Messages
300
Office Version
  1. 365
Platform
  1. Windows
Hey guys,

Trying to do something here that I have done a few times now but I cannot explain results, my code defines "lngLastRow", as I step through the code it clearly shows that it sees row 97 as the last row. However when executing this code it fills down to 397. I have double checked that there is no other data in Column A, all the way along it reports 97 as the last line but every time it completes it take the fill down to 397?

Dim lngLastRow As Long
Sheets("January").Select
lngLastRow = Range("A" & Rows.Count).End(xlUp).Row

'Formula's Month
Range("CS3").Select
ActiveCell.FormulaR1C1 = _
"=TIME(HOUR(RC[-93]),MINUTE(RC[-93]), SECOND(RC[-93]))"
Range("CT3").Select
ActiveCell.FormulaR1C1 = _
"=TIME(HOUR(RC[-88]),MINUTE(RC[-88]), SECOND(RC[-88]))"
Range("CU3").Select
ActiveCell.FormulaR1C1 = "=RC[-1]-RC[-2]"
Range("CV3").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-1]<'Stats Data'!R31C4,""Excellent"",IF(RC[-1]<'Stats Data'!R30C4,""Good"",IF(RC[-1]<'Stats Data'!R29C4,""Acceptable"",""Poor"")))"
Range("CS3:CV3").Select
Selection.AutoFill Destination:=Range("CS3:CV3" & lngLastRow), Type:=xlFillDefault
'Selection.AutoFill Destination:=Range("CS3:CV3" & Range("A" & Rows.Count).End(xlUp).Row)
'Range(Selection, Selection.End(xlDown)).Select

Please someone help, what am I doing wrong here?

Thanks

Fletch
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
It should be
VBA Code:
Selection.AutoFill Destination:=Range("CS3:CV" & lngLastRow), Type:=xlFillDefault
otherwise you are concatenating CV3 with the 97 to get CV397
 
Upvote 0
Solution
Also you can do it like with the need to use autofill.
VBA Code:
Dim lngLastRow As Long
Sheets("January").Select
lngLastRow = Range("A" & Rows.Count).End(xlUp).Row

'Formula's Month
Range("CS3:CS" & lngLastRow).FormulaR1C1 = _
   "=TIME(HOUR(RC[-93]),MINUTE(RC[-93]), SECOND(RC[-93]))"
Range("CT3:CT" & lngLastRow).FormulaR1C1 = _
   "=TIME(HOUR(RC[-88]),MINUTE(RC[-88]), SECOND(RC[-88]))"
Range("CU3:CU" & lngLastRow).FormulaR1C1 = "=RC[-1]-RC[-2]"
Range("CV3:CV" & lngLastRow).FormulaR1C1 = _
   "=IF(RC[-1]<'Stats Data'!R31C4,""Excellent"",IF(RC[-1]<'Stats Data'!R30C4,""Good"",IF(RC[-1]<'Stats Data'!R29C4,""Acceptable"",""Poor"")))"
 
Upvote 0
It should be
VBA Code:
Selection.AutoFill Destination:=Range("CS3:CV" & lngLastRow), Type:=xlFillDefault
otherwise you are concatenating CV3 with the 97 to get CV397
That line is exactly what I have, the other 2 lines below have an apostrophe before them as I tried different things before?
 
Upvote 0
That line is exactly what I have, the other 2 lines below have an apostrophe before them as I tried different things before?
Not quite. You left the "3" in there:
Rich (BB code):
Selection.AutoFill Destination:=Range("CS3:CV3" & lngLastRow), Type:=xlFillDefault
Note Fluff's first reply:
Rich (BB code):
Selection.AutoFill Destination:=Range("CS3:CV" & lngLastRow), Type:=xlFillDefault
 
Upvote 0
Not quite. You left the "3" in there:
Rich (BB code):
Selection.AutoFill Destination:=Range("CS3:CV3" & lngLastRow), Type:=xlFillDefault
Note Fluff's first reply:
Rich (BB code):
Selection.AutoFill Destination:=Range("CS3:CV" & lngLastRow), Type:=xlFillDefault
****! works perfect thank you so much, knew I would be missing something simple just couldn't see it.

Thanks

Fletch
 
Upvote 0
You are welcome. Glad we could help.

I changed the solution to fluff's initial reply, as I was just reiterating what he said/pointed out in that reply.
 
Upvote 0
Glad we could help & thanks for the feedback.
Did you see the simpler way I showed in post#3?
 
Upvote 0

Forum statistics

Threads
1,213,504
Messages
6,114,020
Members
448,543
Latest member
MartinLarkin

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