Last used column with data - ignoring formulas

vaclavvesely

New Member
Joined
Sep 24, 2019
Messages
13
Hi, I have a spreadsheet where is a table filled with formulas returning "" by default and I need macro which will give me a last used cell/column containing any value ignoring cells containing ""

now I use this:

mycell = Cells(3, .Cells(myCell.Row, .Columns.Count).End(xlToLeft).Column)

that returns just end of the table - last column, because all cells are containing "". I need to return number of column containing visible data. Is there any solution?

Thanks
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hi & welcome to MrExcel.
How about
Code:
   MyCell = Cells.Find("*", , xlValues, , xlByColumns, xlPrevious, , , False).Column
 
Upvote 0
Not working, it returns last column of table even if its clear (without value or any formula), cells in the table contains only formatting of the table
 
Upvote 0
Does your table have headers?
 
Upvote 0
This will return the last cell with a value in row 3
Code:
   MyCell = Rows(3).Find("*", , xlValues, , xlByColumns, xlPrevious, , , False).Column
If that is not what you want you will need to explain what you do want.
 
Upvote 0
On the picture is my table, i have a custom function which runs the macro looking for last used column. on the picture can see that it returns end of the table instead of last used column (there is no visible values in that row) - marked red.
 
Upvote 0
On your picture I cannot see what your function is returning as the cell is blank.
Please explain in words what you are trying to do.
 
Upvote 0
And this is my function, it works fine if there are empty cells without formulas.

Code:
Function DATUM_HOTOVO(myCell As Range) As LongApplication.Volatile


    With myCell.Parent


        DATUM_HOTOVO = Cells(3, .Cells(myCell.Row, .Columns.Count).End(xlToLeft).Column)
    End With


End Function

You see that L4 contains a formula returning "" (blank cell with formula)
I4 contains my formula, it returns value from row nr 3 and last used (containing visible data) column - date from header. it works fine if there are blank cells, only a few has an "x" or something inside, but if there is a formula returning "" (not visible value) it returns end of the table (last column at all), so it acts like all cells have visible data, doesn't matter if they are really visible or not. I need to count only with wisible data, ignoring cells which returns "" from formulas.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top