简体   繁体   English

如何 select 基于 2 个单元格的值的工作表和表格

[英]how to select the sheet and table based on the value of 2 cell

I need to enter data using a pseudo-form.我需要使用伪表单输入数据。 What I would like to get is to send the data in a specific table to a specific sheet that are declared by the value of the "Account" and "Bank" cell.我想要得到的是将特定表中的数据发送到由“帐户”和“银行”单元格的值声明的特定工作表。

example, (the language I use in the file is Italian)例如,(我在文件中使用的语言是意大利语)

Pseudo-form for send data Data - Account - Bank - Operazione - Dare - Avere发送数据的伪表格 Data - Account - Bank - Operazione - Dare - Avere

"Account" is a drop-down menu, with the choices "Utente_1, Utente_2, User_3, .. Utente_n (hypoteitically infinite "Utente" values). “帐户”是一个下拉菜单,选项为“Utente_1、Utente_2、User_3、.. Utente_n(假设为无限的“Utente”值)。

"Bank" is a drop-down menu, with the choices "Banca_1, Banca_2, Banca_3... Banca_n (hypothetically infinite values of "Banca") “银行”是一个下拉菜单,有“Banca_1、Banca_2、Banca_3...Banca_n”选项(假设“Banca”的值是无限的)

I tried with this little code and I can only send data to the "Worksheets (" Banca_1 "). Select" I don't know very well with the VBA language, is there anyone who can help me?我尝试使用这个小代码,我只能将数据发送到“工作表(”Banca_1“)。选择”我不太了解 VBA 语言,有人可以帮助我吗?

Dim DATA As Date
Dim ACCOUNT As String
Dim BANK As String
Dim OPERAZIONE As String
Dim DARE As Currency
Dim AVERE As Currency

With Sheets("Home")
    DATA = .Cells(13, 1).Value
    ACCOUNT = .Cells(13, 2).Value
    BANK = .Cells(13, 3).Value
    OPERAZIONE = .Cells(13, 4).Value
    DARE = .Cells(13, 5).Value
    AVERE = .Cells(13, 6).Value 
End With

Call InsOper(DATA, ACCOUNT, BANK, OPERAZIONE, DARE, AVERE)

Dim riga As Integer
Dim v As Variant
riga = 12
Worksheets("Banca_1").Select 

Do
    riga = riga + 1
    v = Sheets("Banca_1").Cells(riga, 2).Value '
Loop While Not IsEmpty(v)

With Sheets("Banca_1") 
    .Cells(riga, 2).Value = DATA
    .Cells(riga, 3).Value = ACCOUNT
    .Cells(riga, 4).Value = BANK
    .Cells(riga, 5).Value = OPERAZIONI
    .Cells(riga, 6).Value = DARE
    .Cells(riga, 7).Value = AVERE
End With

MsgBox ("Ok! Operazione aggiunta con successo")

I have a sheet for each "bank" and on each sheet, there is a table for each "Utente"我对每个“银行”都有一张纸,在每张纸上,每个“Utente”都有一张桌子

I would like to get is to fill in the pesudo-from:我想得到的是填写pesudo-from:

DATA: 12/12/2019数据:2019 年 12 月 12 日

ACCOUNT: User_1帐户:用户_1

BANK: Banca_2银行:Banca_2

OPERAZIONI:PURCHASE操作:购买

DARE: + 25.00 €敢:+ 25.00 欧元

AVERE: -34.00 € AVERE: -34.00 €

and send the data in the sheet called "Banca_2" in the tab called "Utente_1" in the first empty row available.并在可用的第一个空行中名为“Utente_1”的选项卡中发送名为“Banca_2”的工作表中的数据。

It looks like all the changes you need to do are:看起来您需要做的所有更改是:

change Dim BANK As String to Dim BANK As VariantDim BANK As String更改为Dim BANK As Variant

and then all ("Banca_1") to (BANK)然后所有("Banca_1")(BANK)

How it works?这个怎么运作? You declare name of the bank in the user form and then this will select the correct sheet.您在用户表单中声明银行的名称,然后这将 select 正确的表。

Please be aware when using INPUTBOX you need to be precise with the bank name otherwise it will not find the sheet.请注意,在使用INPUTBOX时,您需要准确填写银行名称,否则将找不到表格。

Let me know if it works让我知道它是否有效

When I declare name of Account (utente_1;utente_2,utente_3.....utente_N)and declare name of Bank (Banca_1;Banca_2;Banca_3....Banca_4) in the "operation form" and this select the correct sheet and correct formatted table on the correct sheet.当我在“操作表”中声明账户名称 (utente_1;utente_2,utente_3.....utente_N) 并声明银行名称 (Banca_1;Banca_2;Banca_3....Banca_4) 和此 select 时正确的表格和正确在正确的工作表上格式化表格。 example 例子

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

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