VBA执行sub过程中调用窗口进行填充,全局变量定义失败。

Sub cc()

Dim d As Object '订单号字典
Set d = CreateObject("scripting.dictionary")

Dim qrr(1 To 10000, 1 To 1) '订单号数组
For i = 2 To Sheet1.Cells(Rows.Count, "a").End(xlUp).Row
qrr(i - 1, 1) = Sheet1.Cells(i, 3)
Next

For x = 1 To UBound(qrr) '字典去重
If qrr(x, 1) <> "" Then
d(qrr(x, 1)) = qrr(x, 1)
Else
Exit For
End If
Next x

arr = Application.Transpose(d.items) '字典导入数组
Dim a As String
For i = 1 To UBound(arr)
If arr(i, 1) <> "" Then
a = arr(i, 1)
UserForm1.Show
Else
Exit For
End If
Next

End Sub

Public a As String
Private Sub CommandButton1_Click()
Sheet2.Cells(Sheet2.Cells(Rows.Count, "a").End(xlUp).Row + 1, 1) = a
UserForm1.Hide
End Sub

Private Sub CommandButton2_Click()
Sheet2.Cells(Sheet2.Cells(Rows.Count, "b").End(xlUp).Row + 1, 1) = a
UserForm1.Hide
End Sub

Private Sub CommandButton3_Click()
Sheet2.Cells(Sheet2.Cells(Rows.Count, "c").End(xlUp).Row + 1, 1) = a
UserForm1.Hide
End Sub


sheet1中A列是订单号,想要达到按3个按钮中的一个将对应的订单号填入sheet2中指定列中。但是声明的全局变量为空,无法将a数据插入对应的单元格。