excel用vba巨集中用for迴圈將一列滿足條件的後面加上需要的數值比如

2021-06-26 18:59:55 字數 2721 閱讀 7748

1樓:匿名使用者

直接寫個公式就可以了。假如你那個1在的列是b,在c裡寫公式if(b1=1,"a","空"),然後填充就可以了。

如果一定要用vba,那就讀出來單元格的內容,然後根據內容填充就可以了。

2樓:姓王的

sub aaa()

for i = 1 to range("a65536").end(xlup).row

if cells(i, 1) = "張" and cells(i, 2) = 1 then cells(i, 3) = "a"

next

end sub

如果要判斷b列是否為"空",可用函式 isempty (cells(i, 2)) ,當cells(i,2)沒有任何值時為"真"

3樓:弗爾佈雷斯

不用vba,公式即可解決,具體公式如下

“=if(and(mid(a1,1,1)="張",b1=1),"a","")”

4樓:匿名使用者

dim i as integer

i = 1

for i = 1 to 1000

if activesheet.cells(i,1).value = "" then

exit for

end if

if activesheet.cells(i,1).value = "張" then

activesheet.cells(i,3).value = "a"

end if

next

excel如何用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樓:匿名使用者

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

如何用vba**實現在excel裡同一列資料的累加

9樓:匿名使用者

若資料為sheet1表的b2開始的b列

dim finalrow&

dim sumt&   '所求合

finalrow = sheet1.cells(2,65535).end(xlup).row

sumt = worksheetfunction.sum(range("b2:" & "b" & rinalrow))

10樓:我的王是金閃閃

sub a()

range("b1")=worksheetfunction.sum(range("a1:a1000"))

end sub

Excel使用VBA巨集查詢包含指定內容的值

方法1,用篩選裡面的包含 輸入2002 就可以篩選出來方法2,用輔助列寫公式 left f3,4 同樣可以篩選出來 方法3,用vba寫一串 方法4,寫陣列公式 由上到下為由易變難 sub main x range a65536 end xlup rowredim arr 1 to x,1 to 5 ...

excel的VBA問題 建立巨集,要求輸入學生人數以及各個

總分 平均分用公式更好吧。除非公式無法完成,或者完成的效果不好 速度慢 被修改 否則就不要用vba。弗爾佈雷斯 的回答已經實現基本的內容,如果你想要介面化的東西,可以追問我。excel vba怎樣在點選按鈕後,彈出一個輸入密碼的對話方塊,密碼正確的話執後續程式段,否則結束 excel高手改寫vba加...

Excel怎樣用VBA提取中文字元

gb2312範圍 0xa1a1 0xfefe gbk範圍 0x8140 0xfefe public function hibyte byval word as integer as byte end function public function lobyte byval word as inte...