Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 是否从所选行获取列的值?_Vba_Excel - Fatal编程技术网

Vba 是否从所选行获取列的值?

Vba 是否从所选行获取列的值?,vba,excel,Vba,Excel,因此,我有一个Excel spead表,看起来像这样: 邮政编码------纬度------经度 ZIP列为空。我希望在单击行时能够获得纬度和经度列的值。Lat/Long已填入值 我之所以需要它,是因为一旦获得了这些值,我将使用它从GoogleMap的API获取数据,并用GoogleMap数据中的邮政编码填充ZIP列 当选择该行时,我将如何获取列B和C的值,即纬度和经度?还可以在您的模块范围内构建某种静态数据结构,以便其他SUB可以从明确定义的源中提取lat/lon Type GeoCoord

因此,我有一个Excel spead表,看起来像这样:

邮政编码------纬度------经度

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

我之所以需要它,是因为一旦获得了这些值,我将使用它从GoogleMap的API获取数据,并用GoogleMap数据中的邮政编码填充ZIP列


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

还可以在您的模块范围内构建某种静态数据结构,以便其他SUB可以从明确定义的源中提取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 
'然后在这里做你的URL的东西,如果你想

类似于

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

Lat/Long已经有值了
然后你会问
…去获取…纬度和经度的值
什么??????
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