finding last column from a target row

T

thomas donino

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?
 
J

JP Ronse

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
 
J

Jim Cone

What is targCell ?

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



"thomas donino"
<[email protected]>
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?
 
T

thomas donino

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
 
J

JP Ronse

Lastcolumn = newtargCell.column

thomas donino said:
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
 
C

Chip Pearson

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)
 
J

Jim Cone

You also need to change...

xlRight to xlToRight
--
Jim Cone
Portland, Oregon USA



"thomas donino" <[email protected]>
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
 
T

thomas donino

All fixed, thank you all for the help

Jim Cone said:
You also need to change...

xlRight to xlToRight
--
Jim Cone
Portland, Oregon USA



"thomas donino" <[email protected]>
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
 
Top