+ Reply to Thread
Results 1 to 3 of 3

Excel VBA Last Empty Row VBA paste Array elements

  1. #1

    Excel VBA Last Empty Row VBA paste Array elements

    I have a array and the array size is 1 to 5.

    So far my macro pastes values into Column A, worksheet Sheet1 and Cells
    A2:A6

    - What I would like is a amendment to this macro so it identifies the
    last
    empty cell in column A and then paste the additional array elements in
    that column A list.

    - Because the array data elements is always updated and exported in MS
    Excel, the last
    empty cell in column A is not fixed.

    Is this doable and many thanks in-advance.


    Public Sub AddtoWorksheet()

    Dim myArray(1 To 5) As String


    myArray(1) = "Value1"
    myArray(2) = "Value2"
    myArray(3) = "Value3"
    myArray(4) = "Value4"
    myArray(5) = "Value5"


    Worksheets("Sheet1").Select

    range("A2:A" & UBound(myArray) + 1) =
    WorksheetFunction.Transpose(myArray)


    End Sub


  2. #2
    Dave Peterson
    Guest

    Re: Excel VBA Last Empty Row VBA paste Array elements

    Last used cell and then pastes it one cell below???

    dim NextCell as range
    with activesheet
    set nextcell = .cells(.rows.count,"A").end(xlup).offset(1,0)
    end with


    Kind of like:

    Option Explicit
    Public Sub AddtoWorksheet()

    Dim NextCell As Range
    Dim myArray(1 To 5) As String

    myArray(1) = "Value1"
    myArray(2) = "Value2"
    myArray(3) = "Value3"
    myArray(4) = "Value4"
    myArray(5) = "Value5"

    With Worksheets("sheet1")
    Set NextCell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
    End With

    NextCell.Resize(UBound(myArray) - LBound(myArray) + 1, 1).Value _
    = Application.Transpose(myArray)

    End Sub



    [email protected] wrote:
    >
    > I have a array and the array size is 1 to 5.
    >
    > So far my macro pastes values into Column A, worksheet Sheet1 and Cells
    > A2:A6
    >
    > - What I would like is a amendment to this macro so it identifies the
    > last
    > empty cell in column A and then paste the additional array elements in
    > that column A list.
    >
    > - Because the array data elements is always updated and exported in MS
    > Excel, the last
    > empty cell in column A is not fixed.
    >
    > Is this doable and many thanks in-advance.
    >
    > Public Sub AddtoWorksheet()
    >
    > Dim myArray(1 To 5) As String
    >
    > myArray(1) = "Value1"
    > myArray(2) = "Value2"
    > myArray(3) = "Value3"
    > myArray(4) = "Value4"
    > myArray(5) = "Value5"
    >
    > Worksheets("Sheet1").Select
    >
    > range("A2:A" & UBound(myArray) + 1) =
    > WorksheetFunction.Transpose(myArray)
    >
    >
    > End Sub


    --

    Dave Peterson

  3. #3
    Tom Ogilvy
    Guest

    Re: Excel VBA Last Empty Row VBA paste Array elements

    Public Sub AddtoWorksheet()

    Dim myArray(1 To 5) As String


    myArray(1) = "Value1"
    myArray(2) = "Value2"
    myArray(3) = "Value3"
    myArray(4) = "Value4"
    myArray(5) = "Value5"


    Worksheets("Sheet1").Select
    lastrow = cells(rows.count,1).End(xlup)(2).row
    range("A" & lastrow & ":A" & UBound(myArray) + 1) =
    WorksheetFunction.Transpose(myArray)
    End Sub


    --
    Regards,
    Tom Ogilvy

    <[email protected]> wrote in message
    news:[email protected]...
    > I have a array and the array size is 1 to 5.
    >
    > So far my macro pastes values into Column A, worksheet Sheet1 and Cells
    > A2:A6
    >
    > - What I would like is a amendment to this macro so it identifies the
    > last
    > empty cell in column A and then paste the additional array elements in
    > that column A list.
    >
    > - Because the array data elements is always updated and exported in MS
    > Excel, the last
    > empty cell in column A is not fixed.
    >
    > Is this doable and many thanks in-advance.
    >
    >
    > Public Sub AddtoWorksheet()
    >
    > Dim myArray(1 To 5) As String
    >
    >
    > myArray(1) = "Value1"
    > myArray(2) = "Value2"
    > myArray(3) = "Value3"
    > myArray(4) = "Value4"
    > myArray(5) = "Value5"
    >
    >
    > Worksheets("Sheet1").Select
    >
    > range("A2:A" & UBound(myArray) + 1) =
    > WorksheetFunction.Transpose(myArray)
    >
    >
    > 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