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

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.

Who is Participating?
ClippitConnect With a Mentor Commented:
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
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?
NO_CARRIERAuthor Commented:
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.
NO_CARRIERAuthor Commented:
thanks... worked without any problems at all!
You're welcome!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.