+ Reply to Thread
Results 1 to 3 of 3

ExcelVBA Paste record In next empty next Row

  1. #1

    ExcelVBA Paste record In next empty next Row

    I have a macro which runs the PasteData macro.

    Since the parameters 1 to 5 get populated with new data each time this
    macro is run, I want this macro to move to the next empty row and paste
    the new record into that row. This process or macro is re-run/
    repeated.

    What my macro currently does is only paste to the fixed row cells and
    fails to move to next row of empty cells. A2 to E2 Only

    Public Sub PasteData()

    'Workbooks("Book1").Activate
    'Worksheets("Sheet1").Select

    Dim PCount As Integer

    Cells(1, 2).Select

    PCount = 2

    Cells(PCount, 1).Value = "Par1"
    Cells(PCount, 2).Value = "Par2"
    Cells(PCount, 3).Value = "Par3"
    Cells(PCount, 4).Value = "Par4"
    Cells(PCount, 5).Value = "Par5"


    PCount = PCount + 1

    End Sub


    Is this doable..

    So the table would look like this.

    Table Results:

    Col1 Col2 Col3 Col4 Col5
    -------------------------------------------------------------------------------------------------
    Row1 Par1 Par2 Par3 Par4 Par5
    Row2 Par1 Par2 Par3 Par4 Par5
    Row3 Par1 Par2 Par3 Par4 Par5
    Row4 .... Next Empty row to be filled in when the PasteData macro is
    run again.




    Many thanks... Brenda


  2. #2
    Yngve
    Guest

    Re: ExcelVBA Paste record In next empty next Row

    Hi Brenda

    go to this address

    http://www.rondebruin.nl/copy1.htm

    Regards Yngve


  3. #3
    Lonnie M.
    Guest

    Re: ExcelVBA Paste record In next empty next Row

    If I understand you, each time the macro is run you want it to place
    the data in the next empty row--then use the following:

    Public Sub PasteData()
    Dim PCount As Integer

    Cells(1, 2).Select

    PCount = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row + 1

    Cells(PCount, 1).Value = "Par1"
    Cells(PCount, 2).Value = "Par2"
    Cells(PCount, 3).Value = "Par3"
    Cells(PCount, 4).Value = "Par4"
    Cells(PCount, 5).Value = "Par5"

    End Sub


    The scope/lifetime of your variable 'PCount' lasts only as long as the
    procedure is running, once the procedure is finished the variable
    PCount ceases to exist.

    HTH--Lonnie M.


+ 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