首页 文章

用于将单元格内容复制到输入消息的VBA代码(验证)

提问于
浏览
-1

我根本不是技术人员,但我需要帮助将单元格内容复制到Excel中的数据验证中的输入消息 . 我知道输入消息中的文本字符串有一个限制,很高兴在尝试运行宏之前减少单元格内容 .

谢谢!

美女

1 回答

  • 0

    由于解释的幸运,使用下面的代码,您可以将单元格值复制到另一个单元格 . 通过代码修改,您可能会获得所需的收入 .

    尝试:

    Option Explicit
    Sub test()
    
        Dim str As String
    
        With ThisWorkbook.Worksheets("Sheet1")
    
            str = Application.Clean(Application.Trim(.Range("A1").Value))
    
            'Copy A1 value to A2
            .Range("A2").Value = str
    
            'Use A1 value as message on message box
            MsgBox str
    
            'Use A1 value as data validation on A2
            With Range("A2").Validation
                .Delete
                .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                xlBetween, Formula1:=str
                .IgnoreBlank = True
                .InCellDropdown = True
                .ShowInput = True
                .ShowError = True
            End With
    
        End With
    
    End Sub
    

相关问题