finding last column from a target row

  • Thread starter Thread starter thomas donino
  • Start date Start date
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?
 
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
 
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?
 
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
 
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
 
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)
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top