+ Reply to Thread
Results 1 to 8 of 8

VBA And Finding The First Empty Row

  1. #1
    Registered User
    Join Date
    07-24-2006
    Posts
    18

    VBA And Finding The First Empty Row

    Hi guys,
    Looking for more help! This one should be quite simple though.

    The system in use relies on the user copying and pasting a section from one tab to another. This is 8 columns wide, and 7 rows deep. In the past they've manually entered dates etc etc but I've used formulae to make this more efficient. The problem is, when they copy and paste now, the formulae update and are wrong. So I showed them the Paste Special Feature, which they loved, but then promptly forgot how to use. Anyway, I then decided to use a Macro attached to a button just to do it automatically and be done with it.

    So, I've gotten this far:

    Sub CopyandPasteNewQuarter()


    Range("A9:M29").Select
    Selection.Copy
    Sheets("Stream1").Select
    Range("A258").Select
    Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=False
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=False
    End Sub

    Now I did this just to check the commands would work (they do) and the selection of Cell A258 in stream 1 was done manually as I knew that that was the blank cell I needed. But obviously next quarter it won't be that cell, but A266.
    So what commands would I need to introduce to instruct the macro to find the first blank row in a range, and then insert the block of cells to be copied in there?

    Cheers in advance!!!

  2. #2
    Andy
    Guest

    Re: VBA And Finding The First Empty Row

    "The Cardinal" <[email protected]>
    wrote in message
    news:[email protected]...

    Try using the .End(xldown/xlup/xlright/xlleft) command it is the program
    equialtent of using ctrl & right/left/up/down arrow to navigate.
    Worksheets("Main").Range("A1").End(xlDown) will return the last used cell in
    column A assuming that the data is a complete column.
    If you want the last used cell and the column may contain blanks then try
    Worksheets("Main").Range("A65536").End(xlup) . This will start at the last
    row and work upwards to the first occupied cell.

    To find the first blank cell then just use the appropriate offset.

    Andy



  3. #3
    Registered User
    Join Date
    07-24-2006
    Posts
    18
    Nice! Thanks very much...

  4. #4
    Registered User
    Join Date
    11-20-2008
    Location
    Seattle
    Posts
    1
    So how would I go to the first empty cell in a given row? The Code you gave would take me to the Last filled cell in a row.

  5. #5
    Registered User
    Join Date
    10-14-2009
    Location
    Pretoria, South Africa
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: VBA And Finding The First Empty Row

    So how would I go to the first empty cell in a given row? The Code you gave would take me to the Last filled cell in a row.
    To find the first blank cell then just use the appropriate offset.
    here's how to do so:
    Set MyRange = MyWorkSheet.Range("A1").End(xlDown).Offset(1, 0)

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: VBA And Finding The First Empty Row

    Welcome to the forum.

    Please take a few minutes to read the forum rules, and then edit your post to add code tags.

    Thanks.
    Entia non sunt multiplicanda sine necessitate

  7. #7
    Registered User
    Join Date
    11-01-2012
    Location
    Toowoomba
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    8

    Re: VBA And Finding The First Empty Row

    Another to add to an old post
    To add to the blanks below "G5" ... which has data ...
    will progressively fill the blanks .. skipping other data if it is below and the fill gets to it

    Set Ra = Range("g5").Columns(1)
    Ra.End(xlDown)(2, 1) = "fbert"

    Ra.End(xlDown)(2, 1) = "Herbt"
    Ra.End(xlDown)(2, 1) = "HarryS tomoto"

  8. #8
    Registered User
    Join Date
    11-01-2012
    Location
    Toowoomba
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    8

    Re: VBA And Finding The First Empty Row

    ' A better version to save errors doing first blank after data
    '
    ' to progressively fill blanks in a column .. Past cells with values
    '
    Sub AddIntoRange(Ra As Range, PutV)
    If Ra.Value = "" Then
    Ra.Value = PutV
    ElseIf Ra(2, 1) = "" Then Ra(2, 1) = PutV
    Else
    Ra.End(xlDown)(2, 1).Value = PutV
    End If
    End Sub
    'use like
    Private Sub CommandButton2_Click()
    AddIntoRange Range("j3"), "cte"
    AddIntoRange Range("j3"), 34
    AddIntoRange Range("j3"), 45.67
    AddIntoRange Range("j11"), 11
    AddIntoRange Range("j11"), "freds good"
    AddIntoRange Range("j11"), "freds cool"
    AddIntoRange Range("j11"), "freds handy good"
    AddIntoRange Range("j22"), "I think its OK now maybe "
    AddIntoRange Range("j22"), "seems ok"


    End Sub

+ 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