ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Last Row in Column not working (https://www.excelbanter.com/excel-programming/398253-last-row-column-not-working.html)

terry

Last Row in Column not working
 
OK, I am stuck. I have this line of code that was working:

Doesn't work
lnglastrow = xlSheet.Cells(xlSheet.Rows.Count, "A").End(xlUp).Row

Does work
lnglastrow = xlSheet.Cells(xlSheet.Rows.Count, 1).End(xlUp).Row

Now it only works if I replace the "A" with a 1. This is happening
throughout my code where I do not use a column number. Anyone have any
suggestions?

thanks

Terry

cottage6

Last Row in Column not working
 
Just a guess...
Perhaps Tools - Options - General tab; is the R1C1 reference style checked?
In R1C1 reference style, both rows and columns are numbered numerically.

"Terry" wrote:

OK, I am stuck. I have this line of code that was working:

Doesn't work
lnglastrow = xlSheet.Cells(xlSheet.Rows.Count, "A").End(xlUp).Row

Does work
lnglastrow = xlSheet.Cells(xlSheet.Rows.Count, 1).End(xlUp).Row

Now it only works if I replace the "A" with a 1. This is happening
throughout my code where I do not use a column number. Anyone have any
suggestions?

thanks

Terry


Gary''s Student

Last Row in Column not working
 
I don't see where xlSheet is defined. If "xlSheet" is the name of a specific
worksheet (tab name) then:

Sub ordinate()
Dim ws As Worksheet
Set ws = Sheets("xlSheet")
MsgBox (ws.Cells(Rows.Count, "A").End(xlUp).Row)
MsgBox (ws.Cells(Rows.Count, 1).End(xlUp).Row)
End Sub

--
Gary''s Student - gsnu200747


"Terry" wrote:

OK, I am stuck. I have this line of code that was working:

Doesn't work
lnglastrow = xlSheet.Cells(xlSheet.Rows.Count, "A").End(xlUp).Row

Does work
lnglastrow = xlSheet.Cells(xlSheet.Rows.Count, 1).End(xlUp).Row

Now it only works if I replace the "A" with a 1. This is happening
throughout my code where I do not use a column number. Anyone have any
suggestions?

thanks

Terry


terry

Last Row in Column not working
 
This worked just not the way I expected. Somehow the file had been
corrupted. By checking the R1C1 box it forced me to correct the corrupted
names. When unchecking the box it prompted me to correct a few more.

When done my code worked as before. Thanks for your help.

Terry

"cottage6" wrote:

Just a guess...
Perhaps Tools - Options - General tab; is the R1C1 reference style checked?
In R1C1 reference style, both rows and columns are numbered numerically.

"Terry" wrote:

OK, I am stuck. I have this line of code that was working:

Doesn't work
lnglastrow = xlSheet.Cells(xlSheet.Rows.Count, "A").End(xlUp).Row

Does work
lnglastrow = xlSheet.Cells(xlSheet.Rows.Count, 1).End(xlUp).Row

Now it only works if I replace the "A" with a 1. This is happening
throughout my code where I do not use a column number. Anyone have any
suggestions?

thanks

Terry


terry

Last Row in Column not working
 
Sorry Gary;

I only put the line of code with the error. I had everything defined
similiar to what you have. Not sure why but I had some corrupt chart/graph
names that were causing the error. By checking and unchecking the R1C1 box
it forced me to rename all the problems.

Works now as before.

thanks

Terry

"Gary''s Student" wrote:

I don't see where xlSheet is defined. If "xlSheet" is the name of a specific
worksheet (tab name) then:

Sub ordinate()
Dim ws As Worksheet
Set ws = Sheets("xlSheet")
MsgBox (ws.Cells(Rows.Count, "A").End(xlUp).Row)
MsgBox (ws.Cells(Rows.Count, 1).End(xlUp).Row)
End Sub

--
Gary''s Student - gsnu200747


"Terry" wrote:

OK, I am stuck. I have this line of code that was working:

Doesn't work
lnglastrow = xlSheet.Cells(xlSheet.Rows.Count, "A").End(xlUp).Row

Does work
lnglastrow = xlSheet.Cells(xlSheet.Rows.Count, 1).End(xlUp).Row

Now it only works if I replace the "A" with a 1. This is happening
throughout my code where I do not use a column number. Anyone have any
suggestions?

thanks

Terry



All times are GMT +1. The time now is 04:20 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com