Consulting

Results 1 to 5 of 5

Thread: Writing to the next empty cell

  1. #1
    VBAX Regular
    Joined
    Jun 2007
    Posts
    58
    Location

    Writing to the next empty cell

    I looked around the forums and I found the code but it seems to not work for me

    This is the code I have that runs everytime I want to write to column A.
    [vba] If (Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp) = "") Then
    Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).CopyFromRecordset RS
    End If[/vba]

    A1 has the column header. When the code runs, nothing happens.
    Last edited by taporctv; 06-14-2007 at 01:27 PM.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    seems not to work means what?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Jun 2007
    Posts
    58
    Location
    Well I have a column header in A1. Everytime I call the mentioned code I want to write to the next empty cell, which in this case would be A2. When the code runs, nothing writes to A2.

  4. #4
    VBAX Regular
    Joined
    Jun 2007
    Posts
    58
    Location
    Ok I Ran it step by step and its not entering the If statement. Whats the correct code to determine next empty cell and writing to it.

  5. #5
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    There is no need to test for the first empty cell, as xlUp finds the last filled one.
    [vba] Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1).CopyFromRecordset Rs
    [/vba] Look again at the logic of your original code. It is bound to fail if there is any filled cell in column A
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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