Re: [算表] Excel:如何選取一個單元格後 整行底色變色(VBA)

看板Office作者 (windknife18)時間17年前 (2009/03/24 13:32), 編輯推噓1(102)
留言3則, 2人參與, 最新討論串1/3 (看更多)
試看看合不合適囉 ... Dim Pre_Row As Integer Dim Pre_color As Integer Private Sub Worksheet_SelectionChange(ByVal Target As Range) If (Pre_Row > 0) And (Rows(Pre_Row).Interior.ColorIndex = 35) Then Rows(Pre_Row).Interior.ColorIndex = Pre_color End If x = ActiveCell.Row Pre_Row = x If IsNull(Rows(x).Interior.ColorIndex) Then Pre_color = 0 Else Pre_color = Rows(x).Interior.ColorIndex End If Rows(x).Interior.ColorIndex = 35 End Sub ※ 引述《ntnl (本號)》之銘言: : 軟體: Excel : 版本: 2003 SP3 : 如何可以選取某一儲存格(cell)後,橫向的整行變顏色? : 我原本上網找了一個VBA如下: : Private Sub Worksheet_SelectionChange(ByVal Target As Range) : Rows().Interior.ColorIndex = 0 : x = ActiveCell.Row : Rows(x).Interior.ColorIndex = 35 : End Sub : 但有一個問題 : 我無法再使用變更底色的功能了 : (選取第n行→變更底色為紅色→跳離第n行後,第n行又變回白色底色) : 請問如何改變呢? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.131.84.79

03/24 17:51, , 1F
首次執行會有問題?
03/24 17:51, 1F

03/24 17:51, , 2F
Pre_ 的兩個變數尚未定義
03/24 17:51, 2F

03/24 18:05, , 3F
謝謝 J 大提醒,已加上新版本
03/24 18:05, 3F
文章代碼(AID): #19o71_6l (Office)
文章代碼(AID): #19o71_6l (Office)