如何根據“要交換的三個選定專案”交換“鄰居的完整解決方案”行中的特定單元格?由于要交換的三個選定項中所述的值是隨機生成的,所以我無法在代碼中輸入具體值。比如13、10、15這3個值需要交換,結果可以是5-14- 13 -2-4-8-12- 15 -9- 10 -6-3-7-1-11-5 .
uj5u.com熱心網友回復:
請嘗試使用下一個代碼。但是您的圖片在行和列標題方面不清楚......所以,請調整我構建的范圍以演示它是如何作業的:
Sub SwappingNumbs()
Dim sh As Worksheet, rngS As Range, rng As Range
Dim mtch1, mtch2, mtch3
Set sh = ActiveSheet
Set rngS = sh.Range("B3:D3") 'the range containing numbers used to swap
Set rng = sh.Range("B6:Q6") 'the range containing numbers to be swapped
mtch1 = Application.match(rngS(1, 1), rng, 0) 'it returns position in rng Range
mtch2 = Application.match(rngS(1, 2), rng, 0)
mtch3 = Application.match(rngS(1, 3), rng, 0)
rng(1, mtch1) = rngS(1, 2) 'swapping the numbers...
rng(1, mtch2) = rngS(1, 3)
rng(1, mtch3) = rngS(1, 1)
End Sub
即使您的代碼/解決方案無法按您的意愿作業,您也應該向我們展示您自己嘗試過的內容......
我現在例外,但我希望你知道一個問題必須證明你自己努力解決它。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/486700.html