简体   繁体   中英

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

"Account" is a drop-down menu, with the choices "Utente_1, Utente_2, User_3, .. Utente_n (hypoteitically infinite "Utente" values).

"Bank" is a drop-down menu, with the choices "Banca_1, Banca_2, Banca_3... Banca_n (hypothetically infinite values of "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?

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"

I would like to get is to fill in the pesudo-from:

DATA: 12/12/2019

ACCOUNT: User_1

BANK: Banca_2

OPERAZIONI:PURCHASE

DARE: + 25.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.

It looks like all the changes you need to do are:

change Dim BANK As String to Dim BANK As Variant

and then all ("Banca_1") to (BANK)

How it works? You declare name of the bank in the user form and then this will select the correct sheet.

Please be aware when using INPUTBOX you need to be precise with the bank name otherwise it will not find the sheet.

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. example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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