PC Review


Reply
Thread Tools Rate Thread

How do I goto column B in the current row using VBA?

 
 
LilacSpokane
Guest
Posts: n/a
 
      11th Mar 2008
I need to enter the text "The End" at the end of the worksheet in column B.
I am using ActiveCell.SpecialCells(xlLastCell).Select to find the last cell
in the worksheet. Currently that is cell F379, on my next report the column
may change. Whatever column the last cell turns out to be, I need to enter
"The End" in the last row of Column B. Is there VBA code to goto column B in
the current row?
Thank you
L
 
Reply With Quote
 
 
 
 
Charles Chickering
Guest
Posts: n/a
 
      11th Mar 2008
There are several ways, this would be an easy one:
Range("B" & ActiveCell.Row) = "The End"

and if you want to avoid using the .Select method (a good idea to improve
speed) then try this:
Range("B" & ActiveCell.SpecialCells(xlLastCell).Row) = "The End"
--
Charles Chickering

"A good example is twice the value of good advice."


"LilacSpokane" wrote:

> I need to enter the text "The End" at the end of the worksheet in column B.
> I am using ActiveCell.SpecialCells(xlLastCell).Select to find the last cell
> in the worksheet. Currently that is cell F379, on my next report the column
> may change. Whatever column the last cell turns out to be, I need to enter
> "The End" in the last row of Column B. Is there VBA code to goto column B in
> the current row?
> Thank you
> L

 
Reply With Quote
 
Jim Thomlinson
Guest
Posts: n/a
 
      11th Mar 2008
xlLastCell is not always accurate and generally speaking you don't want to
use it. Try something like this...

Sub test()
Cells(LastRow, "B").Value = "The End"
End Sub

Public Function LastRow(Optional ByVal wks As Worksheet) As Long

If wks Is Nothing Then Set wks = ActiveSheet
On Error Resume Next
LastRow = wks.Cells.Find(What:="*", _
After:=wks.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
If LastRow = 0 Then LastRow = 1

End Function
--
HTH...

Jim Thomlinson


"LilacSpokane" wrote:

> I need to enter the text "The End" at the end of the worksheet in column B.
> I am using ActiveCell.SpecialCells(xlLastCell).Select to find the last cell
> in the worksheet. Currently that is cell F379, on my next report the column
> may change. Whatever column the last cell turns out to be, I need to enter
> "The End" in the last row of Column B. Is there VBA code to goto column B in
> the current row?
> Thank you
> L

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HOW IS COLUMN "K" REFERENCED ON THE CURRENT ROW IN THE GOTO COMMAN mbnspect Microsoft Excel Misc 5 10th Jan 2008 11:50 PM
Goto Current Record problem =?Utf-8?B?Q2hhcyBMYXJnZQ==?= Microsoft Access Form Coding 3 26th Jun 2007 03:03 PM
Goto column A of the ActiveCell ADK Microsoft Excel Programming 3 8th Sep 2006 04:27 PM
If one column is full, goto the next column Biff Microsoft Excel Programming 6 8th Mar 2006 03:49 AM
GoTo Current Record Tom via AccessMonster.com Microsoft Access Macros 1 14th Sep 2005 03:49 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:56 PM.