从所选行中获取列的值?

时间:2016-02-19 21:32:55

标签: vba excel-vba excel

所以我有一个Excel表格,看起来像这样:

ZIP ---------- ----------纬度经度

ZIP列为空。我希望能够在单击该行时获取纬度和经度列的值。 Lat / Long已经填写了值。

我之所以需要这个,是因为一旦获得这些值,我将使用它从Google Map的API http://maps.googleapis.com/maps/api/geocode/json?latlng=29.6412902,-95.0297534&sensor=false中获取数据,并使用Google Map数据中的邮政编码填写ZIP列

如果选择该行,我将如何获取列B和C的值,即纬度和经度?

2 个答案:

答案 0 :(得分:0)

也可以在模块范围内构建某种静态数据结构,以便其他子设备可以从明确定义的源中拉出lat / lon。

Type GeoCoord
Dim Lat as Double
Dim Lon As Double
Dim Zip as Long
End Type

'count how many rows you have...
Dim rowcount as Long
rowcount = 'get creative here

Dim Coords() As GeoCoord
ReDim Coords(1 to rowcount)

For i=1 to rowcount
    With Coords(i)
        .Lat = cells()....' I'm sure you can figure this part out
        .Lon = cells()....' same here
    End With
Next 

'然后在这里做你的网址,如果你想......

类似......

Coords(i).Zip = 'value from google maps API

答案 1 :(得分:0)

Dim rw as Range, Lat, Lngt

For Each rw in selection.rows
    Lat = rw.entirerow.cells(2).value
    Lngt = rw.entirerow.cells(3).value
    rw.entirerow.cells(4).value = GetZip(Lat, Lngt)
Next rw
相关问题