Get Position of Last Column Containing Data with Excel VBA

If you read my latest update on how we can get position of last row containing data, then most probably you already have a glimpse on how we perform the same task with last column containing data in Excel.

The VBA code is the exact replica of the code to get the last row, only this time, we change the row into column.

Function LastColumn() As Long

    Dim ix As Long
    ix = ActiveSheet.UsedRange.Column - 1 + ActiveSheet.UsedRange.Columns.Count
    LastColumn = ix

End Function

The function above will return the appropriate position of the column even when the last column containing data in a hidden state.

The results of this function is the column number, not the column name (1 for A, 2 for B, etc). If what we need is the column name, then we can use the excel column number to column name converter that I wrote before.

This entry was posted in Cells and Range and tagged , , , , , , , , . Bookmark the permalink.

1,147 Responses to Get Position of Last Column Containing Data with Excel VBA

  1. hwsris says:

    Thank ,

    Your code make my idea for find amount row of worksheet.

    Normally I use

    Range("A1", Range("A10000").End(xlUp)).Select

    for my work.

  2. my pleasure hwsris, thanks for coming back :D

  3. Pingback: My Homepage

  4. Pingback: landscape gardeners north london

  5. Pingback: pro flight simulator

  6. Pingback: jobbörse

  7. Pingback: debt consolidation

  8. Pingback: debt consolidation company

  9. Pingback: free mortgage calculator

  10. Pingback: free mortgage calculator

  11. Pingback: tinnitus miracle reviews

  12. Pingback: free credit report

  13. Pingback: Deutschland Job

  14. Pingback: Berufsunfähigkeitsversicherung Vergleich

  15. Pingback: boxfresh

  16. Pingback: sofas

  17. Pingback: conveyancing fees

  18. Pingback: audiovisual

  19. Pingback: hire campervan

  20. Pingback: learn to drive

  21. Pingback: easter study course

  22. Pingback: fancy dress costumes

  23. Pingback: keratosis pilaris remedies

  24. Pingback: air treatment system

  25. Pingback: file sharing

  26. Pingback: tipps zum abnehmen

  27. Pingback: Philips HX 5451

  28. Pingback: parts for pressure washer

  29. Pingback: super bowl 2012

  30. Pingback: Pourquoi juge de tutelle

  31. Pingback: Be2

  32. Pingback: Schließzylinder BKH Sicherheitstechnik ist Spezialist für mechatronische Schließsysteme, Schließanlagen, Zutrittskontrolle, Einbruchmelde- u. Videoüberwachungsanlagen, Rettungswegtechnik, Rauchwarnsysteme, Alarmierungssysteme sowie Briefkastenanlagen und

  33. Pingback: job search in USA

  34. Pingback: fha hamp guidelines

  35. Pingback: best probiotic supplement

  36. Pingback: garden fencing north london

  37. Pingback: gardeners north london

  38. Pingback: Landscape Gardeners London

  39. Pingback: Low Cholesterol Diet

  40. Pingback: Fast Online Loans

  41. Pingback: gsn36a33

  42. Pingback: screenshots

  43. Pingback: Ares

  44. Pingback: Open Office

  45. Pingback: walmart coupon code

  46. Pingback: dentists in burbank

  47. Pingback: kohls coupon

  48. Pingback: Alternative Energy Projects

  49. Pingback: dynamat alternative

  50. Pingback: Eventspion Scooter Tickets

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>