Submit Button to transfer data to another sheet when the month is set.

jothan4859

New Member
Joined
Jan 31, 2022
Messages
15
Office Version
  1. 2016
Platform
  1. Windows
Can anyone help me. I want to know how to add a code when i click submit button if the month is set to january the data will go to the January sheet or if the month is set to February the data will go to the february sheet.
Sub data_input()

ws_output = "JANUARY"

next_row = Sheets(ws_output).Range("A" & Rows.Count).End(xlUp).Offset(1).Row

Sheets(ws_output).Cells(next_row, 1).Value = Range("TIN").Value
Sheets(ws_output).Cells(next_row, 2).Value = Range("SUPPLIER").Value
Sheets(ws_output).Cells(next_row, 3).Value = Range("ADDRESS").Value
Sheets(ws_output).Cells(next_row, 4).Value = Range("AMOUNT").Value
Sheets(ws_output).Cells(next_row, 5).Value = Range("PURCHASE_MONTH").Value
Range("TIN").Value = ""
Range("SUPPLIER").Value = ""
Range("ADDRESS").Value = ""
Range("AMOUNT").Value = ""
Range("PURCHASE_DATE").Value = ""

End Sub

so far this is what i've done my mind is blowing how to make my submit button save the data in a specific sheet

1643657431773.png
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
So you have all this data on a sheet named What?

I see what appears in your image as maybe a UserForm but since you did not mention a Userform.
I assume Range("TIN") for example is on some sheet. So for example the script would send the data from Sheets("Master").Range("TIN") to whatever sheet name you had on sheet "Master").Range("A1") for example.

So I need to know the sheet name where all these Ranges are.

Ranges like:
TIN
Supplier

And such.
And I assume we will put this script in Button on a sheet named "Master"
And the data would be copied to the sheet name you have in Range("A1") of sheet named "Master"

So provide more specific details please.

If your using a Userform then we need the name of the controls on the userform not Range names
 
Upvote 0
sorry it s my first time doing and learning bout this things
1643687398788.png


so this is where the data will go

1643687345440.png
 
Upvote 0
So you have all this data on a sheet named What?

I see what appears in your image as maybe a UserForm but since you did not mention a Userform.
I assume Range("TIN") for example is on some sheet. So for example the script would send the data from Sheets("Master").Range("TIN") to whatever sheet name you had on sheet "Master").Range("A1") for example.

So I need to know the sheet name where all these Ranges are.

Ranges like:
TIN
Supplier

And such.
And I assume we will put this script in Button on a sheet named "Master"
And the data would be copied to the sheet name you have in Range("A1") of sheet named "Master"

So provide more specific details please.

If your using a Userform then we need the name of the controls on the userform not Range names
sorry im really new at this i just watch and learned from youtube.
 
Upvote 0
What is the name of the sheet where these ranges are?
Can I assume it's "Input"

And what is the name of the Range with the sheet name?
Is it "Purchase_Month"

It cannot be "Purchase Month"

See the different no space but Underline


Again what is the name of the Range with sheet name. I do not see that anywhere
So if you enter Alpha in range("A1) all the other ranges will be copied to sheet named Alpha

You said in your last post:
i have named each input field a name such as TIN, SUPPLIER, ETC

I need to know all the names exactly.

Do not say ETC

I can help you but it's important to have exact details or the script will error out
 
Upvote 0
What is the name of the sheet where these ranges are?
Can I assume it's "Input"

And what is the name of the Range with the sheet name?
Is it "Purchase_Month"

It cannot be "Purchase Month"

See the different no space but Underline


Again what is the name of the Range with sheet name. I do not see that anywhere
So if you enter Alpha in range("A1) all the other ranges will be copied to sheet named Alpha

You said in your last post:
i have named each input field a name such as TIN, SUPPLIER, ETC

I need to know all the names exactly.

Do not say ETC

I can help you but it's important to have exact details or the script will error out
Yes its in Input

Yes it is also Purchase_Month

I have named each input field a names such as TIN, SUPPLIER, ADDRESS,AMOUNT and PURCHASE MONTH
 
Upvote 0
I see a Range Named "PURCHASE_DATE"

Range("PURCHASE_DATE").Value = ""

So what is this for:

I see no
Range("PURCHASE_Month").Value = ""

So what do you enter in "Purchase_Month" ?
Do you enter:
January
or 1/7/2022

In your image I see no Purchase Date
 
Upvote 0
I see a Range Named "PURCHASE_DATE"

Range("PURCHASE_DATE").Value = ""

So what is this for:

I see no
Range("PURCHASE_Month").Value = ""

So what do you enter in "Purchase_Month" ?
Do you enter:
January
or 1/7/2022

In your image I see no Purchase Date
OH SORRY about that i change the the code
Range("Purchase_Date").Value = ""
to
Range("PURCHASE_Month").Value = ""

So what do you enter in "Purchase_Month" ?

I enter only January. so when i submit it the data will automatically save in the worksheet named January.
 
Upvote 0
Try this:
VBA Code:
Sub Copy_Me_To_Sheet_Month()
'Modified  2/1/2022  1:07:15 AM  EST
Application.ScreenUpdating = False
Dim ws_output As String
Dim next_row As Long
ws_output = Sheets("Input").Range("ws_output").Value
next_row = Sheets(ws_output).Range("A" & Rows.Count).End(xlUp).Offset(1).Row
Sheets(ws_output).Cells(next_row, 1).Value = Range("TIN").Value
Sheets(ws_output).Cells(next_row, 2).Value = Range("SUPPLIER").Value
Sheets(ws_output).Cells(next_row, 3).Value = Range("ADDRESS").Value
Sheets(ws_output).Cells(next_row, 4).Value = Range("AMOUNT").Value
Sheets(ws_output).Cells(next_row, 5).Value = Range("PURCHASE_MONTH").Value
Range("TIN").Value = ""
Range("SUPPLIER").Value = ""
Range("ADDRESS").Value = ""
Range("AMOUNT").Value = ""
Range("PURCHASE_DATE").Value = ""
Range("PURCHASE_MONTH").Value = ""

Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top