简体   繁体   中英

Copy and create a new line with paste VBA Excel

I want get a line in a exactly posiction on a sheet and transfer this insformation for another line, but in this line i need create this new line above another line and put this information.

The code is bellow:

Public Function getInformationInSheet()

    Dim Hostname As String
    Hostname = ActiveCell.Offset(0, -9).Value
    If MsgBox("Found a equal Mac, it's like " & Hostname & " do you want change this computer information? ", vbYesNo + vbCritical, "Found a equal Mac Address") = vbYes Then
        If ActiveCell.Offset(0, -14).Value <> cmbDepartment.Value Then
            'Rows(ActiveCell.Rows).Cut Rows(findExactlyPosictionDepartment)
            range(ActiveCell.Address).Select
            Selection.Cut
            Cells(range(ActiveCell.Address), 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        End If
    End If



End Function

Public Function findExactlyPosictionDepartment() As String

    findExactlyPosiction = ""
    Worksheets("Full Control").Activate
    range("A3").Select
    Do While ActiveCell.Value <> ""
        If ActiveCell.Value = cmbDepartment Then
            findExactlyPosictionDepartment = ActiveCell.Rows
            Exit Function
        End If
        ActiveCell.Offset(1, 0).Select
    Loop

End Function

But when I runed this code I has a problem in this line:

Cells(range(ActiveCell.Address), 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False

The message is: Type mistach

You must specify a row index, not an instance of the Range class for the Cells property call:

Cells(range(ActiveCell.Address), 1)

with

Cells(1, 1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM