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
 
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
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
What is application.screenupdating means or do?
 
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
can i know what each codes do so i use it again if ever i need that function :D
 
Upvote 0
Well look at the script:
Do you have sheet named:
"Input"
Do you have a range Named "Ws_Output"

This is what you had in your original script.

See you provided a script you found on Youtube so I just made that script work for you.
But you must have all these named ranges already defined on you worksheet named "Input"

Not sure why you wanted to use Named ranges but that will work so I made the script you provided work for you.
 
Upvote 0
w
Well look at the script:
Do you have sheet named:
"Input"
Do you have a range Named "Ws_Output"

This is what you had in your original script.

See you provided a script you found on Youtube so I just made that script work for you.
But you must have all these named ranges already defined on you worksheet named "Input"

Not sure why you wanted to use Named ranges but that will work so I made the script you provided work for you.
what if i dont use named ranges cause i just use it cause i saw it on youtube. what if i use the normal range like C3,c5,c7,c9,c11 in Worksheet(INPUT)
will it be easier to code it?
 
Upvote 0
Going and finding a script that does not work and then wanting us to modify the script so it will work with no specific details is hard to do.

As far as specific details you only said this:
In your original post:
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.

And then posted code that does not work.

So do you think you can modify the script or do we need to start over.
If we are going to start over I need details like where will you enter certain details

and the when you click a button where do you want it to go.
w

what if i dont use named ranges cause i just use it cause i saw it on youtube. what if i use the normal range like C3,c5,c7,c9,c11 in Worksheet(INPUT)
will it be easier to code it?
Not now since I already provided code with named ranges.
So look at my code and make sure all the named ranges are correct if not modify the code or modify the named range name.
And all the named ranges should be on a sheet named "Input"
And excel looks at exact things like:
PURCHASE_MONTH

It cannot be PURCHASEMONTH

It cannot be
 
Upvote 0
Look at these three lines of code:
'Sheets(ws_output).Cells(next_row, 2).Value = Range("SUPPLIER").Value
'Sheets(ws_output).Cells(next_row, 3).Value = Range("ADDRESS").Value

see how I put a ' mark in front of that line of code.
You may try doing that and that line of code will not run.
So you may want to run the script and see if you can figure out which line of code may work and which one will not work.
And read the line and see what might be wrong.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
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