Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Excel - button add value to another cell

0

I have cell sheet1 B2 with customer ID. When I click confirm button I want the cell value B2 to be added to A2 in sheet2.

Then it should put the next number to B2 checking with A2 in sheet2.

Answer
Discuss

Discussion

Waqar

What do you mean by "the next number to B2 checking with A2 in sheet2" please? Can you attach a file to your Question?
John_Ru (rep: 6142) Feb 12, '21 at 11:13 am
John, that means if A2 is ID3 then B3 will be set to ID4. So person who is filling the form do not need to check the ID in the table to add new entry. But i have solved it. I am stuck in the first part. See when I fill the cells then I can click and print the pdf and also save a file to my folder. But I want the data to be saved in another sheet. Please note I am not using any userform. 
Waqar (rep: 8) Feb 12, '21 at 11:39 am
Add to Discussion

Answers

0
Selected Answer

Waqar

Just use this line to copy the value across:

Sheet2.Range("A2").Value = Sheet1.Range("B2").Value
before you use the code (you've worked out) to add the next ID to Sheet1 B2.

Revision 1: If you want to put the value of B2 in Sheet 2 A3 the next time, A4 after that, then this can be used instead:

With Sheet2
r= .Range("A" & Rows.Count).End(xlUp).Row 'find last non-empty cell in column A
.Range("A" & r+1).Value = Sheet1.Range("B2").Value
End With
(assuming you allow the new ID to be the last item in column A).

Hope this solves your problem. Have a good weekend.

Discuss

Discussion

Thanks. not fully done. It is not about one cell. When the user makes another entry to B2 in sheet 1 then the new value should be added to A3 in sheet2. 
The cell B2 in sheet1 is like a template. Every time a user ID is entered, then Save button is clicked. This button saves the sheet as pdf and opens the pdf file. User prints it. Then Clear button clears the cells with name and other details. 

I want:
When the save button is clicked the ID cell (B2) value to be saved in column A in sheet 2. And when the Clear button is clicked the column A in sheet 2 will be checked and the next value will be added to B2 in sheet1, i have done this part. But currently i do not have any data in sheet2. so i need help with that. 
Waqar (rep: 8) Feb 12, '21 at 1:19 pm
I am changing the question. i will share link here. 
Waqar (rep: 8) Feb 12, '21 at 1:22 pm
Please attach your file too. Have no idea what "help" you need on the (empty) sheet 2. Sorry but you need to make your questions clearer. Doubt I'll have time today to answer you again but hopefully others might.
John_Ru (rep: 6142) Feb 12, '21 at 1:25 pm
Feels like you're asking a second question to be honest!
John_Ru (rep: 6142) Feb 12, '21 at 1:27 pm
https://www.teachexcel.com/talk/5139/excel-button-add-value-to-different-sheet
Waqar (rep: 8) Feb 12, '21 at 1:29 pm
See Revision 1 to my Answer (and try to work it out!)
John_Ru (rep: 6142) Feb 12, '21 at 1:33 pm
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login