Excel VBA實現的最簡單的遍歷

2022-05-31 09:48:08 字數 2078 閱讀 7636

昨天公司給我個任務讓做個倉庫物品管理的**,第一次用excel中vba寫了個簡單的小程式

1.需求

弄乙個物品入庫清單和物品領用清單,根據這兩個清單自動生成乙個剩餘物品表

物品入庫清單:

物品領用表:

3.程式

初中寫過vb, 所以vba語法感覺很親切啊

private

sub worksheet_selectionchange(byval target as

range)

'初始化數值

dim rk_row as

integer

'入庫表中的行數

rk_row = 3

dim rk_col as

integer

'入庫表中的列數

rk_col = 3

dim ly_row as

integer

'領用表中的行數

ly_row = 3

dim ly_col as

integer

'領用表中的行數

ly_col = 3

dim num as

integer

'領用數量

num = 0

dim recent as

date

'最近領用日期

recent = #1/1/2000

#

while

len(sheet3.cells(rk_row, 3)) <> 0

'遍歷入庫表的每一行

sheet1.cells(rk_row, 3) = sheet3.cells(rk_row, 3

) sheet1.cells(rk_row,

4) = sheet3.cells(rk_row, 4

) sheet1.cells(rk_row,

5) = sheet3.cells(rk_row, 5

)

while

len(sheet2.cells(ly_row, 3)) <> 0

'遍歷領用表中的每一行

if sheet2.cells(ly_row, 3) = sheet3.cells(rk_row, 3) then

num = num + sheet2.cells(ly_row, 7

)

ifisdate(sheet2.cells(ly_row, 2)) then

recent = sheet2.cells(ly_row, 2

)

endif

endif

ly_row = ly_row + 1

wend

if num <> 0

then

sheet1.cells(rk_row,

2) =recent

elseif recent = #1/1/2000# then

sheet1.cells(rk_row,

2) = "

日期不明

"else

sheet1.cells(rk_row,

2) = "

暫未借出

"end

ifsheet1.cells(rk_row,

6) = sheet3.cells(rk_row, 6) -num

ly_row = 3

num = 0

rk_row = rk_row + 1

wend

end sub

4.結果

6.總結

vba其實還是挺簡單的,上面也就是個初中水平的程式。不過如果他們這個物品領用寫的太雜亂了有很多寫的和倉庫入庫表的名稱都不一樣,都沒有計算上。其實還是用vb或者其他語言做個倉庫管理程式比較好,但不給錢誰做呢【手動攤手】。

最簡單的IdentityServer實現 Api

建立asp.net core web api專案identityserver.easydemo.api 2引用identityserver4.accesstokenvalidation 3新增介面檔案identitycontroller.cs,用於測試授權 如果你直接訪問http localhost...

tensoflow實現最簡單的分類

import numpy as np import tensorflow as tf import random import pickle from collections import counter import nltk from nltk.tokenize import word toke...

js實現最簡單的拖拽

關於js實現最簡單的拖拽 說到拖拽功能,現在各大,中,小型 都基本上有類似的東西,特別是對彈出層拖拽,更是常見的一塌糊塗。其實對於彈出層而言,拖拽最初的目的很單純,就是為了通過拉開層,使被彈出層擋住的內容可見,當然,後來關於拖拽的功能不斷被優化,使得拖拽的應用有了別的意義,最典型的如igoogle的...