Excel - VBA (Identifying Last Row)

I have a complex macro where I declared my last row on the spreadsheet as follows:

Open in new window

The first 6 columns on the spreadsheet only has data in the header and no other information.
The 7th column is where my data actually start.
LastRowGDTS1 = Cells(Rows.Count, 7).End(xlUp).Row


Open in new window


I am inputting formulas into columns 1-6 and coding for it to be copied down to the last row where data is based on the data starting in column 7.
For some reason, the formula is being copied down to approximately 200 extra rows where there is no data.  What am I doing wrong?

Here is how I declared my last row:
LastRowGDTS1 = Cells(Rows.Count, 7).End(xlUp).Row

Open in new window


Here is the code I used to copy the formulas down in columns 1-6
'Copy formulas down
    Range("A2:F2").Select
    If LastRowGDTS1 > 2 Then Selection.AutoFill Destination:=Range("A2:F2" & LastRowGDTS1)
ArisaAnsarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
Here is the text of an article that I found on the web a long time ago. Try one or more of them depending on what your data looks like,

LastRow = Cells.SpecialCells(xlCellTypeLastCell).Row
which is not very exact, because Excel doesn't keep track of the last cell in a very adequate form.
Another method to find the last used row in a particular column is:

lngLastRow = Range("A65536").End(xlUp).Row
or
LstRow = .Cells(Rows.Count, 1).End(xlUp).Row

but this doesn't tell you FOR SURE the last used row in the entire sheet, unless you can be certain that Column A holds the data.
A couple extra methods are more reliable.
LastRow = Cells.Find("*",SearchOrder:=xlByRows,SearchDirection:=xlPrevious).Row¿or¿LastRow = ActiveSheet.UsedRange.Rows.Count
0
ArisaAnsarAuthor Commented:
Thanks for responding.  I used this code to declare my last row but it does not seem to be working.  As mentioned, the 1st column to have data is column 7.

LstRow = .Cells(Rows.Count, 1).End(xlUp).Row

Open in new window


Which is the best way to do this so that it accurately find the last cell in column 7 and then copy the formulas in column A-F down on to that last cell in column 7?
0
NorieAnalyst Assistant Commented:
There's nothing wrong with the way you are finding the last row.

The problem is that you have A2:F2 & LastRowGDTS1.

This means that if LastRowGTDS1 is 10 you will fill A2:F210, rather than A2:F10.

Try this.
 If LastRowGDTS1 > 2 Then Selection.AutoFill Destination:=Range("A2:F" & LastRowGDTS1) 

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ArisaAnsarAuthor Commented:
Thanks.  That worked.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.