Automating Excel: find next available row & populate...

Posted on 2004-09-14
Last Modified: 2010-05-02
hi... I half figured out how to do this, but came into a bit of a snag.

- What I want to do from VB6 is go to a specific worksheet in an Excel workbook.  (i.e. Sheet1)

- Check for the next available row in COLUMN B. (not A).  Meaning, the next row without any information written on it.

- Populate column B, C, E, and F with variables I'll capture within my VB6 application.

- Save / Close the the workbook.

Question by:NO_CARRIER
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2

Expert Comment

ID: 12055882
How far have you been able to get? Can you open the Excel workbook?

When you say next available row in column B, do you mean the next completely empty row, or the next row with no data in B, which may have data in other rows?

Author Comment

ID: 12055942
yeah I got the workbook open.

I'm using with xl.ActiveWorkbook.Sheets("Sheet1") to select Sheet1.

Next row with no data in column B which may have data in other rows is fine.  Whichever is easier to be honest.

Accepted Solution

Clippit earned 250 total points
ID: 12056071
Here's code I built in VBA, but I think it's the same as what you'll need:

Dim objXLApp As New Excel.Application
Dim lngRow As Long

objXLApp.Workbooks.Open ("C:\temp\quickdata.xls") ' change to your filename

With objXLApp.ActiveWorkbook
  With .Worksheets("Sheet1")
    lngRow = .Range("B65535").End(xlUp).Row + 1 ' find the row to use based on column B data
    .Cells(lngRow, 2) = "New Data" ' put the rest of the cell updates here
  End With
End With

Set objXLApp = Nothing

Author Comment

ID: 12064390
thanks... worked without any problems at all!

Expert Comment

ID: 12069514
You're welcome!

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question