+ Reply to Thread
Results 1 to 6 of 6

VB Code to find the 1st blank row in closed workbook

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    VB Code to find the 1st blank row in closed workbook

    Hello:



    I have closed file C:\Temp\Book1.xlsb and it has data in sheet "Data" as shown in attached file.

    I need VB Code to find the 1st blank row # in column A.
    In this case the answer needs to be 18

    Please let me know if you have any questions.
    Thanks.

    Riz
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: VB Code to find the 1st blank row in closed workbook

    Try this code
    Sub Test()
        Dim strPath     As String
        Dim wb          As Workbook
        Dim ws          As Worksheet
        Dim lr          As Long
    
        Application.ScreenUpdating = False
            strPath = ThisWorkbook.Path & "\Book1.xlsb"
            Set wb = Workbooks.Open(strPath)
            Set ws = wb.Worksheets("Data")
            lr = ws.Cells(Rows.Count, 1).End(xlUp).Row + 1
        
            MsgBox lr
            '>~~ Your Code
        
            wb.Close False
        Application.ScreenUpdating = True
    End Sub
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  3. #3
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: VB Code to find the 1st blank row in closed workbook

    This can also be done with a simple formula
    Formula: copy to clipboard
    =MATCH(TRUE,INDEX(A:A="",,),)
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  4. #4
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to find the 1st blank row in closed workbook

    Hello Yasser:

    Thanks a lot, it works

    Alkey: How would you use the above formula to bring row # from closed workbook? Would appreciate if you can explain.

    Riz

  5. #5
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: VB Code to find the 1st blank row in closed workbook

    I am very sorry Riz. I should've read carefully the description about closed workbook. You would need VBA for this.

  6. #6
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: VB Code to find the 1st blank row in closed workbook

    You're welcome. Glad I can offer some help

+ 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. [SOLVED] vba code to copy a specific sheet from a closed workbook to the active workbook
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-01-2017, 03:09 AM
  2. [SOLVED] VB code to find last row in closed workbook
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-24-2017, 04:19 PM
  3. [SOLVED] VB Code to copy data in closed workbook at 1st blank cell
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-04-2016, 01:32 AM
  4. [SOLVED] Trigger code to open 2nd workbook when 1st workbook is attempted to be closed
    By kosherboy in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-30-2015, 11:25 AM
  5. [SOLVED] Code to copy data from a closed workbook and paste in active workbook using named range.
    By paullie1912 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-28-2014, 02:38 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. Counting blank cells in a closed workbook
    By Roan242 in forum Excel General
    Replies: 1
    Last Post: 04-29-2010, 11:05 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