+ Reply to Thread
Results 1 to 2 of 2

VB Coding for Excel

Hybrid View

  1. #1
    Registered User
    Join Date
    03-14-2005
    Posts
    1

    Exclamation VB Coding for Excel

    I have a Command Button in WorkSheet1 and associated VB codes.
    WorkSheet2 contains data stored from time to time.
    I want to add data from worksheet1 to worksheet2.
    The code when executed to find the first empty row
    in WorkSheet2, does not work.
    Rows in WorkSheet1, in which the Command Button
    is located is being searched for the empty row.
    How can I manage this?

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Nkrb1941,

    Here is a macro that will search any worksheet you want and return the first empty row found ( all cells in the row must be empty). If no empty rows are found it returns a zero.
    _________________________________________________________________

    Public Function FirstEmptyRow(ByVal Worksheet_Name As String) As Long

    Dim I As Long
    Dim J As Long
    Dim LastCol As Long
    Dim LastRow As Long

    With Worksheets(Worksheet_Name)
    LastRow = .Rows.Count
    LastCol = .Columns.Count
    For J = 1& To LastRow
    For I = 1& To LastCol
    If IsEmpty(.Cells(J, I)) = False Then Exit For
    Next I
    If I = 257& Then
    FirstEmptyRow = J
    Exit Function
    End If
    Next J
    End With

    End Function

    _________________________________________________________________

    To use it in your code:

    EmptyRow = FirstEmptyRow("Sheet2")

    Hope you can use this,
    Leith Ross

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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