2016-08-29 64 views
0

我試圖用包含特定值的列替換列中的值。到目前爲止,我有兩個獨立工作的查詢,但現在我試圖讓他們一起工作。嘗試了很多東西來整合它們,但目前還沒有運氣。謝謝!根據列標題替換列中的值

Sub FindAddressColumn() 
    Dim rngAddress As Range 
    Set rngAddress = Range("A1:Z1").Find("Location") 
    If rngAddress Is Nothing Then 
    MsgBox "Address column was not found." 
    Exit Sub 
    End If 
    Range(rngAddress, rngAddress.End(xlDown)).Select 
End Sub 

Sub findrep() 
    Dim i As String 
    Dim k As String 
    i = "1" 
    k = "2" 
    Columns("B").Replace what:=i, replacement:=k, lookat:=xlPart, MatchCase:=False 
End Sub 

回答

0

像這樣:

Sub findrep() 
    Dim i As String 
    Dim k As String 
    Dim rngAddress As Range 
    i = "1" 
    k = "2" 

    Set rngAddress = Range("A1:Z1").Find("Location") 
    If rngAddress Is Nothing Then 
     MsgBox "Address column was not found." 
     Exit Sub 
    End If 
    Range(rngAddress, rngAddress.End(xlDown)).Replace what:=i, replacement:=k, lookat:=xlPart, MatchCase:=False 
End Sub 
+0

我會潛入你是怎麼做到準確,但現在它就像一個魅力,非常感謝! – Gertenbol