#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 361
Default Last column

Can someone please tell me how to create a line in vba that activates/selects
the last cell with data in the row that I'm in. So if I have a table that
goes from A1 to Z20 and I'm somewhere in row 3 what script do I put in the
macro to get me to Z3. I will be adding a new column of data every month so
next month I'll be adding data to column AA. Then the next month I'll be
adding to AB and so on. Please don't take the impression that it will be row
3 that I'm in every time though. I just need to get to the last cell in the
particular row that I'm in. So if I'm in row 3 I will need to get to the
last cell in row 3 and not the last cell in any other row.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Last column

Carl,

here's one way:

Cells(ActiveCell.Row, 256).End(xlToLeft).Select


--
Hope that helps.

Vergel Adriano


"carl" wrote:

Can someone please tell me how to create a line in vba that activates/selects
the last cell with data in the row that I'm in. So if I have a table that
goes from A1 to Z20 and I'm somewhere in row 3 what script do I put in the
macro to get me to Z3. I will be adding a new column of data every month so
next month I'll be adding data to column AA. Then the next month I'll be
adding to AB and so on. Please don't take the impression that it will be row
3 that I'm in every time though. I just need to get to the last cell in the
particular row that I'm in. So if I'm in row 3 I will need to get to the
last cell in row 3 and not the last cell in any other row.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Last column

Here is a function that I use to determine the last active column in a sheet.
It uses the Find function, searching for a wildcard (*) starting from cell A1
and searching backwards by column. Therefore the first time it finds data
then the column is returned by the function. If you do not wish to include
formulae then change LookIn:=xlFormulas to LookIn:=xlValues. If you use
xlValues then any formula that results in no data - "" will not be found, so
you may overwrite something. You must pass a worksheet to the function, and
it will return the column number as an integer. Finally, you will need the On
Error part, because any empty sheets will throw up an error, so you use the
Error to set the last active column as 0. This function will give the last
column in the sheet, but not necessarily the last column in your particular
row, and I believe this is what you are looking for. This definitely works
for Excel version 11, and should work in most other recent versions.

I hope it helps!

Private Function Last_Column_Temp(ByVal LocalWorksheet As Worksheet) As
Integer
On Error GoTo LastColumnError
Last_Column_Temp = LocalWorksheet.Cells.Find(What:="*", _
after:=ActiveSheet.Range("A1"), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
On Error GoTo 0
Exit Function
LastColumnError:
On Error GoTo 0
Last_Column_Temp = 0
End Function







"carl" wrote:

Can someone please tell me how to create a line in vba that activates/selects
the last cell with data in the row that I'm in. So if I have a table that
goes from A1 to Z20 and I'm somewhere in row 3 what script do I put in the
macro to get me to Z3. I will be adding a new column of data every month so
next month I'll be adding data to column AA. Then the next month I'll be
adding to AB and so on. Please don't take the impression that it will be row
3 that I'm in every time though. I just need to get to the last cell in the
particular row that I'm in. So if I'm in row 3 I will need to get to the
last cell in row 3 and not the last cell in any other row.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Last column

Sorry, I forgot to mention, to get to the last column in your current row
then call the function using:


ActiveSheet.Cells(ActiveCell.Row, Last_Column_Temp(ActiveSheet)).Select

Now, I hope it helps!


"carl" wrote:

Can someone please tell me how to create a line in vba that activates/selects
the last cell with data in the row that I'm in. So if I have a table that
goes from A1 to Z20 and I'm somewhere in row 3 what script do I put in the
macro to get me to Z3. I will be adding a new column of data every month so
next month I'll be adding data to column AA. Then the next month I'll be
adding to AB and so on. Please don't take the impression that it will be row
3 that I'm in every time though. I just need to get to the last cell in the
particular row that I'm in. So if I'm in row 3 I will need to get to the
last cell in row 3 and not the last cell in any other row.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Referencing date column A & time column B to get info from column TVGuy29 Excel Discussion (Misc queries) 1 January 24th 08 09:50 PM
Search for a column based on the column header and then past data from it to another column in another workbook minkokiss Excel Programming 2 April 5th 07 01:12 AM
Based on a condition in one column, search for a year in another column, and display data from another column in the same row look [email protected] Excel Programming 2 December 30th 06 06:23 PM
Based on a condition in one column, search for a year in another column, and display data from another column in the same row look [email protected] Excel Discussion (Misc queries) 1 December 27th 06 05:47 PM
How can i have all alike product codes in column A be matched with like cities in column B and then add the totals that are in column C [email protected] Excel Programming 4 August 2nd 06 01:10 AM


All times are GMT +1. The time now is 07:25 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"