Tip Printed from ExcelTip.com
Copy a range on the place of the Activecell to a Database sheet using VBA in Microsoft Excel

VBA macro tip contributed by Ron de Bruin, Microsoft MVP - Excel




Sub CopyToActiveCell()
    Dim sourceRange As Range
    Dim destrange As Range
    If Selection.Cells.Count > 1 Then Exit Sub
    Set sourceRange = Sheets("Sheet1").Range("A1:C10")
    Set destrange = ActiveCell
    sourceRange.Copy destrange
End Sub

Sub CopyToActiveCellValues()
    Dim sourceRange As Range
    Dim destrange As Range
    If Selection.Cells.Count > 1 Then Exit Sub
    Set sourceRange = Sheets("Sheet1").Range("A1:C10")
    With sourceRange
        Set destrange = ActiveCell.Resize _
        (.Rows.Count, .Columns.Count)
    End With
    destrange.Value = sourceRange.Value
End Sub

Function LastRow(sh As Worksheet)
    On Error Resume Next
    LastRow = sh.Cells.Find(What:="*", _
                            After:=sh.Range("A1"), _
                            Lookat:=xlPart, _
                            LookIn:=xlFormulas, _
                            SearchOrder:=xlByRows, _
                            SearchDirection:=xlPrevious, _
                            MatchCase:=False).Row
    On Error GoTo 0
End Function

Function Lastcol(sh As Worksheet)
    On Error Resume Next
    Lastcol = sh.Cells.Find(What:="*", _
                            After:=sh.Range("A1"), _
                            Lookat:=xlPart, _
                            LookIn:=xlFormulas, _
                            SearchOrder:=xlByColumns, _
                            SearchDirection:=xlPrevious, _
                            MatchCase:=False).Column
    On Error GoTo 0
End Function