+ Reply to Thread
Results 1 to 7 of 7

VBA find empty row in closed workbook

Hybrid View

  1. #1
    Registered User
    Join Date
    03-12-2014
    Location
    Windsor, UK
    MS-Off Ver
    Excel 2007
    Posts
    43

    VBA find empty row in closed workbook

    Hi All

    Hoping someone can help me out with this. I've managed to find a nice bit of code that allows me to open a closed workbook in order to write data into it from a opened workbook. But I keep getting an Object Required error when i try to run the code.

    What I'm trying to do, is have the code go into the closed workbook, find the first empty row on the sheet, then write the data into it form the sheet 'mydata' which is in the opened workbook, (hope that makes sense?):

    Dim xl0 As New Excel.Application
        Dim xlw As New Excel.Workbook
        Set xlw = xl0.Workbooks.Open("I:\myfilepath\myfile.xlsm")
    
    
     
    emptyRow = WorksheetFunction.CountA(x10.Sheets("Data").Range("A:A")) + 1
    
    
    
    x10.Sheets("Data").Cells(emptyRow, 1).Value = Sheets("mydata").Range("A2").Value
    x10.Sheets("Data").Cells(emptyRow, 2).Value = Sheets("mydata").Range("B2").Value
     
    
    
     
        xlw.Save
        xlw.Close
    
    
        
        Set xl0 = Nothing

    Feel like i'm almost there, just can't figure out the error!

    any help would be greatly appreciated!

    Many thanks in advance for your help
    Last edited by Broobi; 09-08-2015 at 01:43 PM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: VBA find empty row in closed workbook

    Perhaps.
    Dim xl0 As New Excel.Application
    Dim xlw As New Excel.Workbook
    
        Set xlw = xl0.Workbooks.Open("I:\myfilepath\myfile.xlsm")
        
        emptyRow = WorksheetFunction.CountA(xlw.Sheets("Data").Range("A:A")) + 1
    
        xlw.Sheets("Data").Cells(emptyRow, 1).Value = Sheets("mydata").Range("A2").Value
        xlw.Sheets("Data").Cells(emptyRow, 2).Value = Sheets("mydata").Range("B2").Value
     
        xlw.Save
        xlw.Close
        
        Set xl0 = Nothing
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    03-12-2014
    Location
    Windsor, UK
    MS-Off Ver
    Excel 2007
    Posts
    43

    Re: VBA find empty row in closed workbook

    Hi Norie

    I tried what you suggested but I get the error:

    RunTime Error 1004
    
    Unable to get the CountA property of the WorksheetFunction Class
    then it highlights this part of the code in yellow:

    emptyRow = WorksheetFunction.CountA(xlw.Sheets("Data").Range("A:A")) + 1
    Any ideas?

    Many thanks

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: VBA find empty row in closed workbook

    What's in column A of sheet 'Data' in the workbook you are opening?

  5. #5
    Registered User
    Join Date
    03-12-2014
    Location
    Windsor, UK
    MS-Off Ver
    Excel 2007
    Posts
    43

    Re: VBA find empty row in closed workbook

    Hi Norie

    There are two sheets in the workbook. one is empty and hidden, the other only has column headers (for a table) in row 1. that's all

    Thanks

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: VBA find empty row in closed workbook

    I'm confused, why do you want to find the last row in the closed workbook if there's no data in it?

  7. #7
    Registered User
    Join Date
    03-12-2014
    Location
    Windsor, UK
    MS-Off Ver
    Excel 2007
    Posts
    43

    Re: VBA find empty row in closed workbook

    Hi Norie

    Apologies for my delayed response

    I want the other workbook to be where data is stored outside the other workbook. Essentially, the first workbook does all sorts of formulas and workings-out, which are then taken, and transferred into a table into the other workbook (like an audit trail of whats being worked-out)

    I don't want it in the same workbook as i don't want people to see the history

    It's hard to explain without knowing the history of why. But if this is at all possible it would be ideal


    I hope that makes sense?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Update Cell Value from a Closed Workbook to Another Closed Workbook
    By glennchung in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-17-2014, 04:44 PM
  2. Replies: 0
    Last Post: 03-27-2014, 12:38 PM
  3. Replies: 0
    Last Post: 08-25-2013, 11:28 PM
  4. Copy range from closed excel workbook into master file + finding next empty row
    By ralphmeys in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-22-2013, 12:56 PM
  5. Find last row in closed workbook using file path name
    By amazingg64 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-27-2012, 09:22 AM
  6. Code to find value from closed workbook?
    By Yappa in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-23-2012, 01:27 PM
  7. Find data in a closed workbook
    By JonesZoid in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-29-2010, 03:49 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1