【问题标题】:Add fixed text to Excel userform textbox将固定文本添加到 Excel 用户表单文本框
【发布时间】:2018-10-02 22:31:51
【问题描述】:

我想在 Excel 电子表格的特定单元格中的文本框数据中添加额外的固定文本。例如,在文本框中,用户将输入“g0/0”,但在单元格 A2 中应显示“interface g0/0”。这是我目前所拥有的:

Private Sub Populate_Click()
Dim ws As Worksheet
Set ws = Worksheets("Remote")
ws.Range("A2") = Interface.Value

所以我假设我会在最后一行的某个地方添加“接口”,但我不确定语法。 谢谢!

【问题讨论】:

    标签: excel vba textbox userform


    【解决方案1】:

    您可能需要首先对字符串中所需的值进行限制,然后将其设为“A2”的值。假设您的输入文本框在表单上...

    Dim InterfaceValue as string
    InterfaceValue = "interface" &  FormName.InputTextBox.Value
    ws.Range("A2").value = InterfaceValue
    

    【讨论】:

    • 你,我的朋友,是个邪恶的天才!像魅力一样工作!
    【解决方案2】:

    您可以尝试循环所有行,并将固定的字符串值插入单元格。

    例如。

    for(XMLResource 报告:报告) {

            Row row = sheet.createRow(rowNum++);
            sheet.setColumnWidth(0, 1000);
            row.createCell(0)
                    .setCellValue(report.getPage());
    
            row.createCell(1)
                    .setCellValue(report.getTestName());
    
            row.createCell(2)
                    .setCellValue(report.getDescription());
    
            row.createCell(3)
                    .setCellValue(report.getSTATUS());
    
            row.createCell(4)
                    .setCellValue(report.getBuisImpact());
    
            row.createCell(5)
            .setCellValue(report.getVali());
        }
    

    (报告仅是字符串对象)

    【讨论】:

    • 不确定这是否可行。我不想创建单元格。这是一个用户表单,用于将数据添加到特定单元格中的现有 Excel 电子表格中以简化构建配置
    • 明白了!试试 row.getCell(i).setValue(YOUR VALUE),你可以在每次新数据到达时更新你的 Excel 表。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-16
    • 2021-01-23
    • 2016-12-07
    • 1970-01-01
    • 1970-01-01
    • 2021-07-07
    • 2012-01-16
    相关资源
    最近更新 更多