[算表] vba一行改成多行

看板Office作者 (Elisa)時間11月前 (2023/05/30 03:45), 11月前編輯推噓1(1016)
留言17則, 2人參與, 11月前最新討論串1/2 (看更多)
軟體:excel 版本:2019 使用chatgpt寫VBA 只寫一行是正確的 請他運算整張算表就開始錯誤連篇.. 希望版上大大協助 Sub FillVBasedOnOffset() Dim rngNumbers As Range Dim rngOutput As Range Dim targetNumber As Integer Dim outputCount As Integer ' 設置數字範圍和輸出範圍 Set rngNumbers = Range("I1:AL1") Set rngOutput = Range("I2:AL2") ' 儲存 H2 的數值 Dim h2Value As Variant h2Value = Range("H2").Value ' 清空輸出範圍 rngOutput.ClearContents ' 獲取目標數字和輸出次數限制 targetNumber = Range("H2").Value + 2 outputCount = Range("B2").Value ' 填充V For Each cell In rngNumbers If cell.Value = targetNumber Then If outputCount > 0 Then cell.Offset(1).Value = "V" outputCount = outputCount - 1 End If targetNumber = targetNumber + 3 End If Next cell ' 恢復 H2 的數值 Range("H2").Value = h2Value End Sub https://imgur.com/44RX0oR
實際用VBA操作後2列是正確的 如何改成可以運行在第2列~第58列 目標 開始日期+2則打V 之後每個三天打V(打勾日期+3) 打勾的次數不超過B欄的數字 如果有可以用公式的解法更好(可以在googlesheet上執行) 但是CHATGPT寫不太出來... -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.41.61.207 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Office/M.1685389548.A.DD9.html ※ 編輯: instarfree (114.41.61.207 臺灣), 05/30/2023 03:46:35

05/30 06:45, 11月前 , 1F

05/30 06:46, 11月前 , 2F
C2=IF(AND((COLUMN()-COLUMN($B2))+2-$B2>0,MOD((C
05/30 06:46, 2F

05/30 06:46, 11月前 , 3F
OLUMN()-COLUMN($B2))-$B2-2,3)=0,INT((COLUMN()-C
05/30 06:46, 3F

05/30 06:46, 11月前 , 4F
OLUMN($B2)-$B2+1)/3)>0,INT((COLUMN()-COLUMN($B2
05/30 06:46, 4F

05/30 06:46, 11月前 , 5F
)-$B2+1)/3)<=IF(ISBLANK($A2),99,$A2)),"V","")
05/30 06:46, 5F

05/30 06:51, 11月前 , 6F
05/30 06:51, 6F

05/30 06:52, 11月前 , 7F
C2=IF(AND(C$1+2-$B2>0,MOD(C$1-$B2-2,3)=0,INT((C
05/30 06:52, 7F

05/30 06:52, 11月前 , 8F
$1-$B2+1)/3)>0,INT((C$1-$B2+1)/3)<=IF(ISBLANK($
05/30 06:52, 8F

05/30 06:52, 11月前 , 9F
A2),99,$A2)),"V","")
05/30 06:52, 9F

05/30 06:54, 11月前 , 10F
法一不用看行1的數字,法二要看。沒打次數預設99次
05/30 06:54, 10F

05/30 06:56, 11月前 , 11F
更正:列1
05/30 06:56, 11F

05/30 07:00, 11月前 , 12F
可以再精簡,早上腦袋還沒醒= =
05/30 07:00, 12F

05/30 07:02, 11月前 , 13F
=IF(AND(C$1+2-$B2>0,MOD(C$1-$B2-2,3)=0,(C$1-$B2
05/30 07:02, 13F

05/30 07:02, 11月前 , 14F
+1)/3>0,(C$1-$B2+1)/3<=IF(ISBLANK($A2),99,$A2))
05/30 07:02, 14F

05/30 07:02, 11月前 , 15F
,"V","")
05/30 07:02, 15F

05/30 09:29, 11月前 , 16F
也可以用choose搭配陣列溢出
05/30 09:29, 16F

05/30 10:08, 11月前 , 17F
05/30 10:08, 17F
文章代碼(AID): #1aTG3itP (Office)
討論串 (同標題文章)
文章代碼(AID): #1aTG3itP (Office)