Consulting

Results 1 to 5 of 5

Thread: Userform - Copy active row and move to last row

  1. #1
    VBAX Regular
    Joined
    May 2009
    Posts
    76
    Location

    Userform - Copy active row and move to last row

    I have a user form with an account name field, location number field, and various miscellaneous fields. However, I’m at a lost trying to copy the active row and move to the last row in the worksheet.

    Basically:

    I want a copy command button that copys the currect rowdata showing in the userform and paste it to the last row of the worksheet.

    [vba]Private Sub CommandButton1_Click()
    Dim lastrow As Long

    lastrow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Rows(lastrow).Copy Destination:=Rows(lastrow).Offset(1)[/vba]

    something like the above.

    Any help is appreciated

    Kind Regards,

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    [vba]Private Sub CommandButton1_Click()
    Dim lastrow As Long
    If WorksheetFunction.CountA(Cells) = 0 Then Exit Sub
    lastrow = Cells.Find(What:="*", After:=[A1], SearchDirection:=xlPrevious).Row
    Rows(ActiveCell.Row).Copy Destination:=Rows(lastrow + 1)
    Application.CutCopyMode = False
    End Sub
    [/vba]

  3. #3
    VBAX Regular
    Joined
    May 2009
    Posts
    76
    Location
    Thanks for the quick reply..

    I'm having difficutly with the above code due to when viewing the records in the userform, the active cell in the worksheet is stagnet and does not move to the selected row of data per the viewed data record.

    Any way to correct that?

    I'm using the standard get data, put data codes

    Get Data example:
    [VBA]
    Private Sub GetData()
    Dim r As Long
    lastrow = FindLastRow + 1
    If IsNumeric(RowNumber.Text) Then
    r = CLng(RowNumber.Text)

    Else
    ClearData
    MsgBox "Illegal Row Number"
    Exit Sub
    End If

    If r > 1 And r <= lastrow Then
    UserForm1.ActName.Value = Cells(r, 1).Value
    UserForm1.Formnum.Value = Cells(r, 2).Value
    UserForm1.ActEdNo.Value = Cells(r, 3).Value
    UserForm1.RepDate.Value = Cells(r, 4).Value
    UserForm1.RepDueDate.Value = Cells(r, 5).Value
    UserForm1.MailAdd.Value = Cells(r, 6).Value
    UserForm1.CITY1.Value = Cells(r, 7).Value

    UserForm1.STATE1.Value = Cells(r, 8).Value

    UserForm1.Formnum.Value = RowNumber.Text - 1
    'DisableSave

    ElseIf r = 1 Then
    ClearData
    Else
    ClearData
    MsgBox "Invalid Row Numer"
    End If
    [/VBA]

  4. #4
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Set the userform's ShowModal property to False or add the vbModeless parameter to your userform1.show method.

  5. #5
    VBAX Regular
    Joined
    May 2009
    Posts
    76
    Location
    How do I reverse the method.. While I'm in the userform or selectling the first, previous, next, or view last record I’d like to row in the worksheet to match the record I'm viewing.

    Kind Regards,

Posting Permissions

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