2017-02-24 85 views
-1

这绝对是一个新手问题,但真的让我非常沮丧。我无法弄清楚为什么我会在将值赋给一个变量后丢失了值。奇怪的是,显示cell_location没有问题,但cell_locaton1在消息框中变为空。奇怪的丢失字符串值

Sub COPYCELL() 
    Dim bottomCell As Range 
    Dim offsetCell As Range 
    Dim cell_location As String 
    Dim cell_location1 As String 
    Dim SC As String 

    With ActiveSheet 
     Set bottomCell = .Cells.Find(what:="XXX") 
     Set offsetCell = .Cells.Find(what:="YYY") 
     cell_location = "A" & bottomCell.Row 
     cell_locaton1 = "A" & offsetCell.Row 

     SC = cell_location & ":" & cell_location1 
     MsgBox SC 

    End With 
End Sub 
+5

这个问题的最佳答案是两个字:Option Explicit。试试:) –

+1

cell_locaton1 =“A”中有一个错字&offsetCell.Row –

回答

1

Typo?从底部声明中遗漏我。

Dim cell_location1 As String 

cell_locaton1 = "A" & offsetCell.Row 
+0

是的。我是一个白痴。谢谢!我一直坚持了几个小时。 – pau

+0

@pau这是不幸的,因为明确的输入选项会花费你几秒钟,或者几分钟更多的声明变量。 –