ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   finding last column from a target row (https://www.excelbanter.com/excel-programming/432471-finding-last-column-target-row.html)

thomas donino

finding last column from a target row
 
Set newtargcell = Range("A2")
Set newtargcell = targCell.End(xlRight)

the last produces an error, shouldnt it find the last cell to the right of
row2?

JP Ronse

finding last column from a target row
 
Thomas,

You probably defined an object "newtargcell" but you are calling "targcell"

Try ...
Set newtargcell = range("A2")..End(xlRight)

Could you check already my feedback on previous question?

Wkr,

JP

"thomas donino" wrote in message
...
Set newtargcell = Range("A2")
Set newtargcell = targCell.End(xlRight)

the last produces an error, shouldnt it find the last cell to the right of
row2?




Jim Cone[_2_]

finding last column from a target row
 
What is targCell ?

row2 or Column 2 ?
--
Jim Cone
Portland, Oregon USA



"thomas donino"

wrote in message
...
Set newtargcell = Range("A2")
Set newtargcell = targCell.End(xlRight)

the last produces an error, shouldnt it find the last cell to the right of row2?

thomas donino

finding last column from a target row
 
Sub testcol()
Set newtargCell = Range("A2")
Set newtargCell = newtargCell.End(xlRight)
Lastcolumn = newtargCell
MsgBox "Last column is" & newtargCell
End Sub

is the correct code, but doesn't work

"Jim Cone" wrote:

What is targCell ?

row2 or Column 2 ?
--
Jim Cone
Portland, Oregon USA



"thomas donino"

wrote in message
...
Set newtargcell = Range("A2")
Set newtargcell = targCell.End(xlRight)

the last produces an error, shouldnt it find the last cell to the right of row2?


JP Ronse

finding last column from a target row
 
Lastcolumn = newtargCell.column

"thomas donino" wrote in message
...
Sub testcol()
Set newtargCell = Range("A2")
Set newtargCell = newtargCell.End(xlRight)
Lastcolumn = newtargCell
MsgBox "Last column is" & newtargCell
End Sub

is the correct code, but doesn't work

"Jim Cone" wrote:

What is targCell ?

row2 or Column 2 ?
--
Jim Cone
Portland, Oregon USA



"thomas donino"

wrote in message
...
Set newtargcell = Range("A2")
Set newtargcell = targCell.End(xlRight)

the last produces an error, shouldnt it find the last cell to the right
of row2?




Chip Pearson

finding last column from a target row
 

Lastcolumn = newtargCell


This sets Lastcolumn to the VALUE of newtargCell, NOT the column
number of that cell. Try

Lastcolumn = newtargCell.Column

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Sun, 16 Aug 2009 09:55:01 -0700, thomas donino
wrote:

Sub testcol()
Set newtargCell = Range("A2")
Set newtargCell = newtargCell.End(xlRight)
Lastcolumn = newtargCell
MsgBox "Last column is" & newtargCell
End Sub

is the correct code, but doesn't work

"Jim Cone" wrote:

What is targCell ?

row2 or Column 2 ?
--
Jim Cone
Portland, Oregon USA



"thomas donino"

wrote in message
...
Set newtargcell = Range("A2")
Set newtargcell = targCell.End(xlRight)

the last produces an error, shouldnt it find the last cell to the right of row2?


Jim Cone[_2_]

finding last column from a target row
 
You also need to change...

xlRight to xlToRight
--
Jim Cone
Portland, Oregon USA



"thomas donino"
wrote in message
...
Sub testcol()
Set newtargCell = Range("A2")
Set newtargCell = newtargCell.End(xlRight)
Lastcolumn = newtargCell
MsgBox "Last column is" & newtargCell
End Sub

is the correct code, but doesn't work




"Jim Cone" wrote:
What is targCell ?

row2 or Column 2 ?
--
Jim Cone
Portland, Oregon USA




"thomas donino"

wrote in message
...
Set newtargcell = Range("A2")
Set newtargcell = targCell.End(xlRight)

the last produces an error, shouldnt it find the last cell to the right of row2?


thomas donino

finding last column from a target row
 
All fixed, thank you all for the help

"Jim Cone" wrote:

You also need to change...

xlRight to xlToRight
--
Jim Cone
Portland, Oregon USA



"thomas donino"
wrote in message
...
Sub testcol()
Set newtargCell = Range("A2")
Set newtargCell = newtargCell.End(xlRight)
Lastcolumn = newtargCell
MsgBox "Last column is" & newtargCell
End Sub

is the correct code, but doesn't work




"Jim Cone" wrote:
What is targCell ?

row2 or Column 2 ?
--
Jim Cone
Portland, Oregon USA




"thomas donino"

wrote in message
...
Set newtargcell = Range("A2")
Set newtargcell = targCell.End(xlRight)

the last produces an error, shouldnt it find the last cell to the right of row2?




All times are GMT +1. The time now is 06:03 PM.

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