在MsgBox中返回新生成的单元格值

问题描述 投票:1回答:1

[每当我运行此代码时,它都会生成一个序号。

我想在MsgBox中显示新的序列号,但是会打印旧的序列号。

Private Sub ToggleButton1_Click()

    Dim reponse As VbMsgBoxResult
    Dim REVISIONRNCAUTO As Workbook
    Dim Sheet2 As Worksheet
    Dim cell_value As String
    Set REVISIONRNCAUTO = ActiveWorkbook
    Set Sheet2 = REVISIONCRNAUTO.Worksheets(2)

    cell_value = Sheet2.Cells(4, "A").Value & Sheet2.Cells(4, "B").Value

    If CheckBox1.Value = True And CheckBox4.Value = True And CheckBox7.Value = True And CheckBox2.Value = False And CheckBox3.Value = False _
       And CheckBox6.Value = False And CheckBox5.Value = False And CheckBox8.Value = False And CheckBox9.Value = False And CheckBox10.Value = False And CheckBox11.Value = False And CheckBox12.Value = False _
       And CheckBox13.Value = False And CheckBox14.Value = False And CheckBox15.Value = False Then

        Sheet2.Activate

        reponse = MsgBox("Êtes-vous sûr de vouloir générer ce RNC?", vbYesNo + vbQuestion, "Enregistrement RNC")
        If reponse = vbYes Then

            Sheets("Sheet2").Range("B4").Select
            ActiveCell.EntireRow.Insert shift:=xlDown

            Sheets("Sheet2").Range("B4:E4").Select
            Selection.Borders.Weight = xlThin

            Sheets("Sheet2").Range("B4").Select
            ActiveCell.Value = "=b5+1"

            Sheets("Sheet2").Range("A4").Select
            Selection.Borders.Weight = xlThin
            ActiveCell.Value = "E"

        Else
            Exit Sub
        End If
     End If

     MsgBox ("Le nouveau RNC enregistré est le : " & cell_value)
excel vba
1个回答
0
投票

设置后,您不会更改cell_value的值。

它们不会像Excel公式那样永久链接。一旦更改了它所基于的单元格,就必须再次设置它。

cell_value =线除了当前位置,还放在Else的前面。

© www.soinside.com 2019 - 2024. All rights reserved.