Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9194513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:25:54+00:00 2026-06-17T21:25:54+00:00

Q: How do I get the last used column in a specific row from

  • 0

Q: How do I get the last used column in a specific row from an Excel sheet.
While this is a simple task using Excel VBA its more difficult using Powerpoint VBA.

Here is an example of my Excel sheet

enter image description here

Steps to reproduce

  • create & save a new Excel sheet like my example above
  • open a new PowerPoint presentation & hit ALT+F11 for the VBA editor
  • insert the code below and customize the path to your test Excel file in line 3
  • execute the code line per line using F8
Sub findlastcolumn()

    Set objExcel = CreateObject("Excel.application")
    Set objWorkbook = objExcel.Workbooks.Open("C:\Users\<USERNAME>\Desktop\data.xls")

    objExcel.Visible = True

    'works in Powerpoint VBA but delivers the wrong column
    lastcol = objWorkbook.Sheets(1).UsedRange.Columns.Count

    'produces an error in Powerpoint VBA
    'but works in Excel VBA, correct column in Excel VBA
    lastcol = objWorkbook.Sheets(1).Cells(1, 254).End(Direction:=xlToLeft).Column

    'produces an error in Powerpoint VBA
    'but works in Excel VBA, and wrong column in Excel VBA too
    lastcol = objWorkbook.Sheets(1).Cells.SpecialCells(xlLastCell).Column

    'wrong column. Powerpoint VBA' find method differs from Excel' find method
    'searchdirection isn't available in Powerpoint VBA
    lastcol = objWorkbook.Sheets(1).Rows(1).Find(what:="*", _ 
        after:=objWorkbook.Sheets(1).Cells(1, 1), searchdirection:=xlPrevious).Column

    objExcel.Quit
    Set objWorkbook = Nothing
    Set objExcel = Nothing

End Sub

Desired result: I want to get lastcol = 3

The comments in my code show you what I have tried so far and what error they produce.
I’m thankful for any advice.

There is no PowerPoint 2003 tag? O.o

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:25:55+00:00Added an answer on June 17, 2026 at 9:25 pm

    The Excel specific code you posted should actually work and give you the same result as if you execute it in Excel.

    The reason you do get error message is most likely that you did not in include the Excel reference in your Powerpoint VBA! You do use Late Binding, so it’s generally not necessary to reference this library. However, the VBA compiler does not know the internal values of the Excel constants/enums xlToLeft, xlLastCell and xlPrevious and therefore produces the error!

    Two options to solve your issue:

    1. Include the Microsoft Excel library in your references
    2. Instead of using the Excel specific conmstants/enums, just use their underlying numerical values. To do so, go to the Excel Visual Basic editor. In the Immediate window (Ctrl–G), type ? xlToLeft – and you’ll get the result (in this example -4159). Then replace the name in your Powerpoint VBA with the number and it should work. (For better code readability, I usually leave the name of the constant in a comment in the same line, e.g.
      lastcol = objWorkbook.Sheets(1).Cells.SpecialCells(11).Column 'xlLastCell = 11
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I do not get the last version of node-http-proxy working (this used to work
how to get last row of excel in POI and append blank row and
How would I get last 12 digits of a string using mysql? Let's say
How can I get last year's start and end date using PHP code? Is
I have some date and I want to get last x day before this
I want to dynamically collapse table column to specific width (10 px in this
Maybe a simple question, I'm trying to get a result from a table where
I have got an Excel file in this form : Column 1 Column 2
I am deleting a column from one of the frequently used tables in my
I get this erorr eerytime I try to create a user from the console.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.