在EXCEl中,用VBA實現單元格顏色改變

時間 2022-03-06 21:25:03

1樓:一郎大神

dim i%,r%

whit sheets["表名稱"]

r=.range["a65536"].end(xlup).rowfor i=1 to r

if .cells(i,1) .value<20 then.cells(i,1).font.colorindex=4eed if

if .cells(i,1) .value>19 and .cells(i,1) .value<41 then

.cells(i,1).font.colorindex=6end if

if .cells(i,1) .value>40 then.cells(i,1).font.colorindex=3end if

next i

end with

2樓:在流坑村行走的彼岸花

這兒就能搞定了  不需要vba

3樓:匿名使用者

條件格式就能搞定了,舍易求難啊

excel如何用vba設定符合條件的單元格填充顏色為紅色?

4樓:刀劍上的舞者

材料/工具:excel2010

1、開啟excel**,按下【alt+f11】組合快捷鍵開啟vba編輯器,也可以點選選單欄上面的【開發工具】,【visual basic】開啟vba編輯器。

2、點選vba編輯器選單欄上面的【插入】、【模組】,也可以在編輯器上面使用【alt+i+m】組合快捷鍵插入「模組」。

4、在excel**上面的【開始】、【填充顏色】、【其他顏色】,在」顏色「對話方塊的【自定義】裡面就可以找到,改變數值就可以看到新增的顏色。

5、在vba編輯器的工具欄裡面點選「執行」圖示即可執行程式,條件滿足的行將會自動填充所設定的顏色。

6、vba自動填充滿足條件的行的顏色完成。

5樓:慶年工坊

sub xx()

m = activesheet.usedrange.item(activesheet.usedrange.count).row

n = activesheet.usedrange.item(activesheet.usedrange.count).column

for i = 12 to n

if cells(1, i) <> "" then

for j = 2 to 11

if cells(1, j) = cells(1, i) then exit for

next

for k = 2 to m

if cells(k, i) <> "" and cells(k, i) = cells(k, j) then cells(k, i).interior.colorindex = 3

next

end if

next

end sub

6樓:zzllrr小樂

'寫了這段**,你應該能看懂

sub color_by_zzllrr

for i=4 to 12

for j=1 to 10

if cells(i,12+j*2)=cells(i,j+1) then

cells(i,12+j*2).font.color=vbredend if

next j

next i

end sub

7樓:百

public c   '定義全域性變數c

private sub worksheet_selectionchange(byval target as range)

on error resume next

dim one, c1%

if target.column > 1 and target.column < 12 then c = target.

column '如果第一次選中的單元格在b-k列之間,則記錄此時列號

if c = 0 then exit sub

c1 = target.column

if c1 > 13 then

for one = 4 to 12 '因為你的資料在第4行到第12行之間

if cells(one, c1) = cells(one, c) then '比較兩列的資料

cells(one, c1).interior.colorindex = 3 '塗顏色

end if

next    '比較下一個

c = 0 '清空c

end if

end sub

用法: **貼上在表1的**頁中

1、在資料1中要比較的那列隨便選一個單格

2、在資料2中要比較的那列隨便選一個單格

8樓:匿名使用者

我做了一個,沒辦法發給你

excel中如何用vba將某個單元格填充顏色,也就是高亮顯示。

9樓:太極健

如你的資料在a列,**如下。

sub aa ()

for x =1 to range("a65536").end(xlup).row'建立迴圈

if cells(x,1)=6 then'判斷單元格值cells(x,1).interior.colorindex = 3'單元格值等於6時,該單元格填充紅色

end if

next x

end sub

10樓:匿名使用者

excel 97中工作表是由行和列組成的二維**,我們可以通過系統提供的語句activesheet.cells(i,j),將當前工作表中的第i行第j列所在的單元格中的資料取出

如何用vba程式設計,將excel**裡a列的內容根據單元格背景顏色做出調整 10

11樓:匿名使用者

我給你一個判斷單元格是否有底色的**,你在根據自己的要求修改**即可sub abc()

dim rng as range, rng1 as rangedim y as integer

set rng = range("a1:d9") ''''a1:d9區域

for each rng1 in rng

y = rng1.interior.colorindex ''''單元格顏色標記數

if y > 0 then msgbox rng1.address ''''如果y>0,則提示該單元格的地址

next

end sub

excel中如何用vba將某個單元格填充顏色?

12樓:太極健

如你的資料在a列,**如下。

sub aa ()

for x =1 to range("a65536").end(xlup).row'建立迴圈

if cells(x,1)=6 then'判斷單元格值cells(x,1).interior.colorindex = 3'單元格值等於6時,該單元格填充紅色

end if

next x

end sub

excel用vba如何在表中,當點選任意一個單元格,這個表中與點選單元格內容相同的所有單元格的背景色改變。

用vba如何實現在excel中某一區域內所有空單元格中填充顏色

電子** vba,如何用**給單元格設定顏色?

13樓:匿名使用者

cells(1, 1).font.colorindex = 3 '字的顏色號為3 紅色

cells(1, 1).interior.colorindex = 3 ' 背景的顏色為3 紅色

cells(2, 1).font.color = rgb(0, 255, 0) '字的顏色綠色

cells(2, 1).interior.color = rgb(0, 0, 255) '背景的顏色藍色

14樓:木子見星

網頁連結  這裡有, 還有怎麼使用的教程

如何在excel中用巨集(VBA)實現VLOOKUP的功能

慶年工坊 function myvlookup val,rg as range,n as integer,f as boolean arr rg if f then for i ubound arr to 1 step 1if val arr i,1 thenmyvlookup arr i,n en...

在EXCEL中。用VBA程式編寫

函安白 自定義函式如下,請新增到要使用的excel檔案的vba 模組中function iscircletext byval 字串 as string do while len 字串 1if left 字串,1 right 字串,1 then iscircletext no exit functio...

EXCEL中用LOOKUP如何實現

lookup函式只能在規定的範圍內實現這個要求,如果要返回200 299為2,300至399為3,則要新增對應資料,公式如下。lookup a1,所以還是改用別的函式更為方便。如。int a1 100 trunc a1 100,rounddown a1 100,floor a1 100,1 這些函式...