简体   繁体   English

VBA用于将文本从单个未移动的单元格复制到粘贴到另一个单元格,每个粘贴/循环向下移动一个单元格

[英]VBA function to copy text from a single un-moving cell to paste to another cell, moving down one cell each paste/loop

I am trying to make a worksheet that will eventually be used for route optimization using an original base address and a list of locations. 我正在尝试制作一个工作表,最终将使用原始基地址和位置列表进行路由优化。 I currently have a macro that uses google maps api that will list distances and duration from the origin address to all of the addresses on the list. 我目前有一个使用google maps api的宏,它会列出从原始地址到列表中所有地址的距离和持续时间。 I am trying to pull the shortest duration found using the google maps api and have the associated address be used as the new origin so I can compare the distances and duration again. 我想尝试使用谷歌地图api找到最短的持续时间,并将相关的地址用作新的原点,这样我就可以再次比较距离和持续时间。 I have the worksheet setup so that the shortest duration address replaces the previous origin address, but I need to be able to copy and paste each of the new origin addresses into their own cells to essentially make a list of the order that they are used. 我有工作表设置,以便最短的持续时间地址替换以前的原始地址,但我需要能够将每个新的原始地址复制并粘贴到它们自己的单元格中,以基本上列出它们的使用顺序。

Basically, consider that cell G16 is where the first origin address is stored and after the first run of the distance/duration macro G16 will update to whatever address is the least furthest away from the origin address, therefor becoming the new origin. 基本上,考虑单元格G16是存储第一起始地址的位置,并且在距离/持续时间宏G16的第一次运行之后,宏G16将更新到距离原始地址最远的任何地址,因此成为新的原点。 I then need to copy that origin address to cell G18 and repeat the distance/duration macro with each subsequent address from G16 being copied down 1 cell/row at a time. 然后我需要将该原始地址复制到单元格G18并重复距离/持续时间宏,G16中的每个后续地址一次向下复制1个单元/行。 ie, the 1st address is copied to G18, the 2nd to G19, 3rd to G20, until all of the addresses are listed. 即,第一个地址被复制到G18,第二个到G19,第三个到G20,直到列出所有地址。 The number of addresses is also variable and changes with each week so the range is inconsistent. 地址数也是可变的,每周都会变化,因此范围不一致。

Please let me know if this makes any sense as it is kind of complicated to explain. 如果这有任何意义,请告诉我,因为解释起来很复杂。 Thank you! 谢谢!

这应该工作:

Cells(Rows.count, "G").End(xlUp).Offset(1, 0).Value = Range("G16").Value

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM