【问题标题】:Get value(s) of column(s) from the selected row?从所选行获取列的值?
【发布时间】:2016-02-19 21:32:54
【问题描述】:

所以我有一个看起来像这样的 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的值,这是纬度和经度的值?

【问题讨论】:

  • Lat/Long already has values 然后你问...go about obtaining the values of...Latitude and Longitude 什么??????

标签: vba excel


【解决方案1】:

不妨在您的模块范围内构建某种静态数据结构,以便其他潜艇可以从明确定义的来源中提取纬度/经度。

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 

'如果你愿意,那就在这里做你的 URL 的东西......

类似...

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

【讨论】:

    【解决方案2】:
    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
    

    【讨论】:

      猜你喜欢
      • 2013-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多