Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
I'm looking for a way to find the last used column in a given row. I've tried a couple methods without much luck. I've tried to replicate the lastrow = Cells(Rows.Count, "c").End(xlUp).Row for rows with lastcolumn = cells("5", columns).End(xlLeft).Column but this never seems to work for me, one problem i think i might be having is that i can't reference a specific row number, as i'm using a variable to identify the row name as well. any suggestions? |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Craig,
Try something like: '============= Public Sub Tester() Dim rw As Long Dim lastCol As Long rw = 2 '<<==== CHANGE lastCol = Cells(rw, Columns.Count).End(xlToLeft).Column MsgBox lastCol End Sub '<<============= --- Regards, Norman "Craig" wrote in message oups.com... Hi I'm looking for a way to find the last used column in a given row. I've tried a couple methods without much luck. I've tried to replicate the lastrow = Cells(Rows.Count, "c").End(xlUp).Row for rows with lastcolumn = cells("5", columns).End(xlLeft).Column but this never seems to work for me, one problem i think i might be having is that i can't reference a specific row number, as i'm using a variable to identify the row name as well. any suggestions? |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Craig,
Try this... Public Function LastColumn(r As Long) If Cells(r, Columns.Count).Value = "" Then LastColumn = Cells(r, Columns.Count).End(xlToLeft).Column Else LastColumn = Columns.Count End If End Function You can call this function from a worksheet formula or a subroutine. NickH |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
finding the largest value for a name in a column and then returningthe result from a different column | Excel Worksheet Functions | |||
Finding the closest number in column A and take the value in column B | Excel Worksheet Functions | |||
Finding all matches in column B with datalist in column A | Excel Programming | |||
Output from a userform finding the right column. column | Excel Programming | |||
finding and reporting in column A, where a series of column reaches zero | Excel Programming |