简体   繁体   English

Excel Vba计数器功能

[英]Excel Vba Function for a counter

I need to keep memorized a progressive number in a function. 我需要在函数中记住一个递增数字。

I have a file with some invoices to be repeated in a new sheet, the invoices have a progressive number. 我有一个包含一些发票的文件,该发票要在新的工作表中重复,发票有一个递进编号。 This number is relevant to avoid double registration in the new sheet. 此数字与避免在新工作表中重复注册有关。 How can I keep this number in a function and start from it for updating. 如何将这个数字保留在函数中并从中开始进行更新。

At the moment I am using a cell in a worksheet (but I 'd like to use a function) 目前,我正在工作表中使用一个单元格(但我想使用一个函数)

protocol_number = activecell.value (I get the prot nr in a sub)
range("a1000")=protocol_number

different sub
if Range("a1000") = activecell.value then 

Msgbox "the protocol number has been registered yet"
else
update code

Thanks for helping me 谢谢你帮我

I think I was not so clear. 我想我不太清楚。 I'm sorry about that. 对此我感到抱歉。 I'll try to clarify it. 我会尽力澄清。

2 workbooks First one is a summary of a huge detailed (2nd) workbook for a big Financial Company, with several invoices entered by an employee. 2个工作簿第一个是一个大型金融公司庞大而详细的(第二个)工作簿的摘要,其中有一个员工输入了几张发票。 Invoice numbers are different and alphanumeric (we are in Italy and it's possible). 发票编号是不同的,并且字母数字(我们在意大利,并且有可能)。 But it is mandatory in Italian accounting to set all the invoice entering by a progressive number called protocol number. 但是在意大利会计中,必须通过称为协议编号的渐进编号设置所有发票输入。 This protocol number marks the line of input with invoice number, amount, company, vat, and date of issue. 该协议号用发票号,金额,公司,增值税和开具日期标记输入行。

Transferring the data to the summary workbook I always let the code start from the beginnig (as the pick up of invoices is always retrieved from a different Financial operating software, which creates a new excel file with all invoices, even the ones already reported on the summary workbook), keep looking to the protocol nr, match with the last one entered and from the matched one keep updating the summary workbook. 将数据传输到摘要工作簿中,我总是让代码从beginnig开始(因为发票的提取始终是从其他Financial操作软件中检索的,该软件会创建一个包含所有发票的新excel文件,即使已在发票上报告的也是如此)摘要工作簿),继续查找协议nr,与输入的最后一个匹配,并从匹配的书中继续更新摘要工作簿。 (remember the protocol number in the only data not transferred in the summary workbook, if it was I could match it) Now I used to put the last protocol number used in a cell which can be cancelled or overwritten or other. (如果可以,请记住摘要工作簿中唯一未传输的数据中的协议号,如果可以的话)现在我将最后使用的协议号放在可以取消或覆盖或其他形式的单元格中。 So I was asking if there is a function (and you clerly said is not possible) that keeps the last protocol number entered and on the next updating match it with the invoice workbook and go further with updating if needed. 所以我在问是否有一个功能(您不能说是不可能的)保持输入的最后一个协议编号,并且在下一次更新时将其与发票工作簿匹配,并在需要时进一步进行更新。 I do not post the code as I am still using the cell as protocol number keeper. 我没有发布代码,因为我仍在使用该单元作为协议号保持器。

Hope this is clear 希望这很清楚

You need a so-called static variable : 您需要一个所谓的静态变量

Sometimes you want to retain the value of a variable in Excel VBA when a procedure ends. 有时,当过程结束时,您想在Excel VBA中保留变量的值。 You can achieve this by using the Static keyword. 您可以通过使用Static关键字来实现。

Static protocol_number As Integer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM