2017-02-24 123 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這是不幸的,因爲明確的輸入選項會花費你幾秒鐘,或者幾分鐘更多的聲明變量。 –