Autofill down to last used row not working

rfletcher35

Active Member
Joined
Jul 20, 2011
Messages
282
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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
65,587
Office Version
  1. 365
Platform
  1. Windows
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
 
Solution

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
65,587
Office Version
  1. 365
Platform
  1. Windows
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"")))"
 

rfletcher35

Active Member
Joined
Jul 20, 2011
Messages
282
Office Version
  1. 365
Platform
  1. Windows
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?
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
60,028
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

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
 

rfletcher35

Active Member
Joined
Jul 20, 2011
Messages
282
Office Version
  1. 365
Platform
  1. Windows
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
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
60,028
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

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.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
65,587
Office Version
  1. 365
Platform
  1. Windows
Glad we could help & thanks for the feedback.
Did you see the simpler way I showed in post#3?
 

Forum statistics

Threads
1,147,474
Messages
5,741,342
Members
423,656
Latest member
Medrok2021

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
Top