請懂VBA的朋友幫我用VBA在excel裡面編寫個計算器,只要加法的就可以了

2022-06-26 23:40:32 字數 5991 閱讀 3045

1樓:張光越

private sub worksheet_selectionchange(byval target as range)

if [f6] <> "=" then exit sub

static temp

static w, j

r1 = target.row

c1 = target.column

if r1 > 2 and r1 < 7 and c1 > 3 and c1 < 7 then

a = ""

select case r1 & c1

case 34

a = 1

case 35

a = 2

case 36

a = 3

case 44

a = 4

case 45

a = 5

case 46

a = 6

case 54

a = 7

case 55

a = 8

case 56

a = 9

case 64

a = 0

case 65

temp = [d1]

[d1] = 0

j = 1

case 66

if j = 1 then

[d1] = [d1] + temp

w = 0

j = 0

else

[d1] = 0

end if

end select

if a <> "" then

if w = 1 then

[d1] = [d1] & a

else

[d1] = a

w = 1

end if

end if

[a1].select

end if

end sub

sub 初始化計算器外觀()

cells.clear

cells.select

selection.rowheight = 44.25

range("d3").select

activecell.formular1c1 = "1"

range("e3").select

activecell.formular1c1 = "2"

range("f3").select

activecell.formular1c1 = "3"

range("d4").select

activecell.formular1c1 = "4"

range("e4").select

activecell.formular1c1 = "5"

range("f4").select

activecell.formular1c1 = "6"

range("d5").select

activecell.formular1c1 = "7"

range("e5").select

activecell.formular1c1 = "8"

range("f5").select

activecell.formular1c1 = "9"

range("d6").select

activecell.formular1c1 = "0"

range("e6").select

activecell.formular1c1 = "+"

range("f6").select

activecell.formular1c1 = "="

range("d1:f2").select

with selection

.horizontalalignment = xlcenter

.verticalalignment = xlcenter

.wraptext = false

.orientation = 0

.addindent = false

.indentlevel = 0

.shrinktofit = false

.readingorder = xlcontext

.mergecells = false

end with

selection.merge

range("d1:f6").select

with selection.font

.name = "宋體"

.size = 36

.strikethrough = false

.superscript = false

.subscript = false

.outlinefont = false

.shadow = false

.underline = xlunderlinestylenone

.themecolor = xlthemecolorlight1

.tintandshade = 0

.themefont = xlthemefontminor

end with

with selection

.horizontalalignment = xlgeneral

.verticalalignment = xlcenter

.wraptext = false

.orientation = 0

.addindent = false

.indentlevel = 0

.shrinktofit = false

.readingorder = xlcontext

end with

with selection

.horizontalalignment = xlcenter

.verticalalignment = xlcenter

.wraptext = false

.orientation = 0

.addindent = false

.indentlevel = 0

.shrinktofit = false

.readingorder = xlcontext

end with

selection.font.bold = true

with selection.font

.color = -16776961

.tintandshade = 0

end with

with selection.interior

.pattern = xlnone

.tintandshade = 0

.patterntintandshade = 0

end with

with selection.interior

.pattern = xlsolid

.patterncolorindex = xlautomatic

.themecolor = xlthemecoloraccent6

.tintandshade = 0.399975585192419

.patterntintandshade = 0

end with

range("d1:f6").select

selection.borders(xldiagonaldown).linestyle = xlnone

selection.borders(xldiagonalup).linestyle = xlnone

with selection.borders(xledgeleft)

.linestyle = xlcontinuous

.colorindex = 0

.tintandshade = 0

.weight = xlthin

end with

with selection.borders(xledgetop)

.linestyle = xlcontinuous

.colorindex = 0

.tintandshade = 0

.weight = xlthin

end with

with selection.borders(xledgebottom)

.linestyle = xlcontinuous

.colorindex = 0

.tintandshade = 0

.weight = xlthin

end with

with selection.borders(xledgeright)

.linestyle = xlcontinuous

.colorindex = 0

.tintandshade = 0

.weight = xlthin

end with

with selection.borders(xlinsidevertical)

.linestyle = xlcontinuous

.colorindex = 0

.tintandshade = 0

.weight = xlthin

end with

with selection.borders(xlinsidehorizontal)

.linestyle = xlcontinuous

.colorindex = 0

.tintandshade = 0

.weight = xlthin

end with

range("d1:f2").select

end sub

private sub worksheet_activate()

初始化計算器外觀

end sub

把上面**貼到一個表的模組上,返回就可以使用了

2樓:

在excel的vba裡做加法計算器?有這必要嗎?首先excel本身sum函式就有加法計算功能,沒必要在vba中做。

即使放到vba中,加法也就是c=a+b這種寫法。如果是在vba中做個計算器出來,那也沒這個必要,因為windows系統本身就有計算器,在vba中只要呼叫就可以了,用shell "calc.exe"即可。

在excel中如何用vba到達這個效果,加法

3樓:涐吢銥舊囿儚

嘿嘿,我已經給樓主搞定了。

4樓:弗爾佈雷斯

先不說這個容易與否吧,光看這麼多文字頭就大了,建議你適當用截圖+文字的說明方法,還有就像 qy1219no2 樓主你最好先把能解決的問題解決掉,例如你那個ab兩個陣列合的,這個完全可以用公式解決,然後再把你不能解決的問題發上了

不然光發這麼一大段文字,誰看的都眼暈。

5樓:

看得頭大!!!

建議樓主把你能解決的問題解決了,把不能解決的問題列出,最好上個圖或者檔案,否則,真的很少有人去仔細研究你的全部問題。

6樓:

我頭像有號碼,加我再說吧

請求高人幫忙寫一個定時清理excel快取的vba,謝謝。其實也不一定要vba,只要能加速excel執行的就可以了

7樓:匿名使用者

excel執行20多分鐘後就慢?

你裡面有什麼?

我想在excel裡面用vba編寫一個查詢的程式! 10

8樓:櫻_桃子

因為你沒說具體,我就寫一段比較通用的了。

dim maxcol as integermaxcol = 10 '所要檢查的表的最後一列for i = 1 to activesheet.rows.count

for j = 1 to maxcol

if trim(cells(i,j)) = "查詢條件" thenmsgbox "查詢到了。"

end if

next

next

用vba在beforeclose事件觸發的程式中寫了一句if sheets 1 cells c

目測 c d 可能是 0 的值,做一下判斷,如果 0 就不執行 您發的截圖裡好像寫的是 sheets 1 cells c,8 這種語法格式在vba裡是錯誤的,必須寫成 sheets 1 cells c,8 後面的同樣的錯誤。原因 變數 c 或 d 等於或者小於0 sheets 1 重新複製下工作表名...

關於VBA的超級簡單的問題,請高手幫忙

這個要配合工作簿的開啟事件。excel vba滑鼠動作問題,請高手來幫忙!有點意思,做了個 option explicit dim strpre,s as string dim lastrange as string dim lcount as long private sub worksheet ...

求EXCEL用VBA的IF條件語句與FOR迴圈語句的基本語法,不要複製貼上,要最簡單說明下就行了

最簡單的來兩句,不明白請追問 for的用法是這樣的 for i 1 to n 語句.next i 這樣的功能是,使裡面的 語句 執行n次,每次i的值都不同,分別是1 n,用來完成固定次數的重複。if的用法是這樣的 if 條件 then 語句1.else 語句2.end if 這樣的功能是判斷條件是否...