小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

Excel讓選定單元格所在行和列顏色突出高亮顯示

 昵稱7665211 2014-01-12

Excel讓選定單元格所在行和列顏色突出高亮顯示


當(dāng)工作表里面的數(shù)據(jù)量大的時(shí)候,鼠標(biāo)選定當(dāng)前單元格后,要想弄清楚它對(duì)應(yīng)的行和列實(shí)在是不方便。如果能做到excel自動(dòng)以高亮突出顏色的方式來(lái)顯示當(dāng)前行和列的話,那該多方便啊,哈哈。其實(shí)excel中可以做到這個(gè)效果的,方法有兩種:條件格式和vba。

使用條件格式

下面將使用條件格式實(shí)現(xiàn)當(dāng)前單元格和當(dāng)前單元所在行或列突出顯示的效果。

在公式中使用了cell函數(shù),并將screenupdation屬性的值設(shè)置為true以實(shí)現(xiàn)屏幕更新。

在thisworkbook模塊中輸入如下代碼: private sub workbook_sheetselectionchange(byval sh as object, byval target as range) application.screenupdating = true end sub 當(dāng)然,如果只想在工作表中實(shí)現(xiàn)突出顯示的效果,將application.screenupdating = true代碼輸入到worksheet_selectionchange事件中。

接下來(lái),在excel中選擇菜單“格式——條件格式”命令,彈出“條件格式”對(duì)話框。

在“條件”下拉框中選擇“公式”并在右側(cè)中輸入下面相應(yīng)的公式,然后點(diǎn)擊“格式”按鈕,設(shè)置相應(yīng)的格式,完成后,按“確定”按鈕。

下面是相應(yīng)的公式及其作用: (1)公式“=cell("address")=address(row(),column())”,突出活動(dòng)單元格,如下圖1所示。

 

圖1

(2)公式“=cell("row")=row()”,突出單元格所在行,如下圖2所示。

 

圖2

(3)下面的公式突出到當(dāng)前單元格為止的相應(yīng)行和列,呈反l形,如下圖3所示。 “=or(and(cell("row")=row(),cell("col")+1>column()),and(cell("col")=column(),cell("row")+1>row()))”

 

圖3

(4)在“條件格式”對(duì)話框中對(duì)所選單元格區(qū)域設(shè)置兩個(gè)如下所列的公式條件,將呈反l形突出顯示到當(dāng)前單元格為止的相應(yīng)行和列,且當(dāng)前單元格背景色改變、字體加粗顯示,如下圖4所示。 “=cell("address")=address(row(),column())” “=or(and(cell("row")=row(),cell("col")+1>column()),and(cell("col")=column(),cell("row")+1>row()))”

  圖4  示例文檔見(jiàn) 使用條件格式自動(dòng)突出顯示.xls。

使用vba代碼
(1) 突出顯示至當(dāng)前單元格所在的行和列,呈反l形。在需要設(shè)置此功能的工作表模塊中輸入下面的代碼:
private sub worksheet_selectionchange(byval target as range)
  dim icolor as integer
  '注:如果工作表中有想要保留的條件格式,則不要使用本程序
  '忽略用戶選擇單元格區(qū)域時(shí)可能產(chǎn)生的錯(cuò)誤
  on error resume next
  icolor = target.interior.colorindex
  if icolor < 0 then
    icolor = 36
  else
    icolor = icolor + 1
  end if
  '避免字體顏色與突出色相同
  if icolor = target.font.colorindex then icolor = icolor + 1
  cells.formatconditions.delete
  '水平突出色
  with range("a" & target.row, target.address)
    .formatconditions.add type:=2, formula1:="true"
    .formatconditions(1).interior.colorindex = icolor
  end with
  '垂直突出色
  with range(target.offset(1 - target.row, 0).address & ":" & _
    target.offset(-1, 0).address)
    .formatconditions.add type:=2, formula1:="true"
    .formatconditions(1).interior.colorindex = icolor
  end with
end sub
注意,此代碼運(yùn)行后,將清除所在工作表中含有的條件格式。示例文檔見(jiàn) 用顏色自動(dòng)突出顯示當(dāng)前單元格行列1.xls。uploadfiles/2006-10/1027319888.rar
(2) 突出顯示當(dāng)前單元格所在的行和列。在需要設(shè)置此功能的工作表模塊中輸入下面的代碼:
private sub worksheet_selectionchange(byval target as range)
  '可帶條件格式,但不能復(fù)制/剪切/粘貼操作
  with target.parent
    .cells.interior.colorindex = 0
    .columns(target.column).cells.interior.colorindex = 35
    .rows(target.row).cells.interior.colorindex = 35
  end with
end sub
注意,此代碼運(yùn)行后,在當(dāng)前工作表中不能進(jìn)行復(fù)制、剪切和粘貼功能。示例文檔見(jiàn) 用顏色自動(dòng)突出顯示當(dāng)前單元格行列2.xls。uploadfiles/2006-10/1027121529.rar
(3) 突出顯示當(dāng)前單元格所在的行和列。在需要設(shè)置此功能的工作表模塊中輸入下面的代碼:
private sub worksheet_change(byval target as range)
  if application.cutcopymode <> false then
    application.cutcopymode = false
    call colorband(target)
  end if
end sub
‘- - - - - - - - - - - - - - - - - - - - -
private sub worksheet_selectionchange(byval target as range)
  if application.cutcopymode = false then
    call colorband(target)
  else
    exit sub
  end if
end sub
‘- - - - - - - - - - - - - - - - - - - - -

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多