看板 Visual_Basic 關於我們 聯絡資訊
各位大大好,小弟有個問題請教 小弟想讓符合條件的值上面添加一列, 所以小弟寫了以下的代碼 lastrow = Cells(Rows.Count, "A").End(xlUp).Row For i = 2 To lastrow If Cells(i, "A").Value = 1 Then Rows(i).Insert 執行幾次迴圈後,他始終都是把列加在第一筆符合條件的上面加一行列 請問為何會這樣呀? https://imgur.com/a/LOvemop -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 163.23.80.141 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Visual_Basic/M.1630658017.A.216.html
O2000: Insert執行完後,Row的index就會改變了 09/03 16:54
kumasan123: for 少了一個next,另外迴圈順序可以反過來寫。 09/04 13:39
waiter337: if那行改成 09/07 15:00
waiter337: aa: If Cells(i, "A").Value = 1 Then rows(i).insert 09/07 15:01
waiter337: 接著上一行沒分段 goto aa 09/07 15:01
waiter337: 接著上一行沒分段 :goto aa 09/07 15:02