运行时错误5:VBA中的过程调用无效

时间:2018-06-11 06:28:54

标签: vba excel-vba excel

我正在尝试将选定的组合框值复制到相邻的单元格中,当我编写相同的代码时我正在

  

运行时错误5.

Private Sub CommandButton1_Click()

    Dim projworkbook As Workbook
    Dim page1 As Worksheet
    Dim lColumn As Long
    Dim CopiedColName  as String

    Set projworkbook = ActiveWorkbook
    Set page1 = projworkbook.Worksheets("Project_Creation")

    lColumn = page1.Cells(13, Columns.Count).End(xlToLeft).Column 'Getting the last used column number

    If lColumn > 26 Then
        CopiedColName = Chr(Int((lColumn - 1) / 26) + 64) & Chr(Int((lColumn - 1) Mod 26) + 65) 'Converting the col number to col name
    Else
        CopiedColName = Chr(lColumn + 64)
    End If

    Me.Cells("CopiedColName" & 4).Text = Me.ComboBox1.Text '-> I am getting run time error at this line

End Sub

1 个答案:

答案 0 :(得分:0)

使用:

Me.Range(CopiedColName & 4).Value = Me.ComboBox1.Text '-> I am getting run time error at this line