开发者

Loop through list to copy batches of like values

开发者 https://www.devze.com 2023-03-16 19:30 出处:网络
I\'m trying to copy batches of rows, based upon one column\'s values. The worksheet looks like this (sorted by the first column):

I'm trying to copy batches of rows, based upon one column's values.

The worksheet looks like this (sorted by the first column):

A  5  blue  
A  6  yellow  
B  3  red  
B  2  blue  

The loop has 3 primary steps:

  1. Copy all rows beginning with a value, e.g. rows 1-2, which both begin with "A"
  2. Paste rows into an email (I know how to do this)
  3. Move to the value, B, and copy all rows starting with B

I won't know the 开发者_高级运维values of Column A, as they will change each time. Is there a way I can still write this loop?


2 possible approaches:

1: Rather than thinking of it as copying all the "A" rows at once, have a build string that you add to for each row, and then when you hit a new value for the first column, flush the build string into the email. That way its a single loop with a condition check in there.

2:

  • Maintain a startPos. set it to 1.
  • Loop through first col till value changes.
  • Copy startRow - currentRow - 1 to email.
  • set startPos = currentRow.
  • Repeat.
0

精彩评论

暂无评论...
验证码 换一张
取 消