在Excel中翻译整个列并粘贴结果到下一列

在Excel中翻译整个列并粘贴结果到下一列。我的代码如下:

Sub test() Dim s, r As Range, l As String For Each s In Range("A2:A3").Cells l = s **Range("B2:B3").Cells = translate_using_vba(s, l)** Next s End Sub Public Function translate_using_vba(str, l) As String ' Tools Refrence Select Microsoft internet Control Dim IE As Object, i As Long, j As Long Dim inputstring As String, outputstring As String, text_to_convert As String, result_data As String, CLEAN_DATA Set IE = CreateObject("InternetExplorer.application") ' TO CHOOSE INPUT LANGUAGE inputstring = "auto" ' TO CHOOSE OUTPUT LANGUAGE outputstring = "en" text_to_convert = str 'open website IE.Visible = False IE.navigate "http://translate.google.com/#" & inputstring & "/" &outputstring & "/" & text_to_convert Do Until IE.ReadyState = 4 DoEvents Loop Application.Wait (Now + TimeValue("0:00:5")) Do Until IE.ReadyState = 4 DoEvents Loop CLEAN_DATA = Split(Application.WorksheetFunction.Substitute(IE.Document.getElementById("result_box").innerHTML, "</SPAN>", ""), "<") For j = LBound(CLEAN_DATA) To UBound(CLEAN_DATA) result_data = result_data & Right(CLEAN_DATA(j), Len(CLEAN_DATA(j)) - InStr(CLEAN_DATA(j), ">")) Next IE.Quit translate_using_vba = result_data End Function 

问题:它工作正常,但是每次都会覆盖B列中的结果。 我怎么能存储B2值,然后移动到B3?

尝试这个:

 Set r = Range("B2") ' Initial (starting) cell For Each s In Range("A2:A3").Cells l = s r.value = translate_using_vba(s, l) Set r = r.Offset(1, 0) 'Next row Next s