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

看板Office作者 (windknife18)時間17年前 (2009/03/24 18:04), 編輯推噓2(202)
留言4則, 1人參與, 最新討論串2/3 (看更多)
想說把那兩個和在一起,忘了一開始會有問題 .... Dim Pre_Row As Integer Dim Pre_color As Integer Private Sub Worksheet_SelectionChange(ByVal Target As Range) If (Pre_Row > 0) Then If (Rows(Pre_Row).Interior.ColorIndex = 35) Then Rows(Pre_Row).Interior.ColorIndex = Pre_color End If 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 ※ 引述《windknife18 (windknife18)》之銘言: : 試看看合不合適囉 ... : 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 20:07, , 1F
推! 效果很好~!
03/24 20:07, 1F

03/24 20:09, , 2F
只是顏色是暫存的 存檔後會消失(不知有解乎)
03/24 20:09, 2F

03/24 20:11, , 3F
即 第n行紅色 現游標移至n 存檔關閉 重開後就非紅色
03/24 20:11, 3F

03/24 20:22, , 4F
嗯 大概要在BeforeClose裡先存 大約可想像之
03/24 20:22, 4F
文章代碼(AID): #19oB12W8 (Office)
文章代碼(AID): #19oB12W8 (Office)