How can I use a command button in excel to set the value of multiple cells in one click

0 votes

I'm trying to set up a spreadsheet with an activex command button that, when clicked, modifies the value of many cells. I feel like I'm missing something very basic here. However, it always seems to simply run the first line that affects a cell value when clicked, ignoring the others. I'm not sure how to get all of the lines to function, but each one works on its own if I put it at the top.

My code is as follows:

Private Scan As Integer

Private Sub CommandButton1_Click()                      
Scan = Sheet1.Cells(5, "A") + 1                         
Sheet1.Cells(5, "A") = Scan                             
Sheet1.Cells(8, "A") = Scan + 1
Sheet2.Cells(Scan + 4, "A") = Scan                      
Sheet2.Cells(Scan + 4, "A") = Sheet1.Cells(19, "B")     
End Sub

The button modifies cell A5 as desired if I use the above, but it has no effect on cell A8 or any other cell on sheet 2 if I use the above. Since if I comment out the line altering cell A5 suddenly the one changing cell A8 works, I'm quite sure it's not a problem with the individual lines.

Oct 24, 2022 in Others by Kithuzzz
• 38,000 points
797 views

1 answer to this question.

0 votes

Try this:

Private Scan As Integer

Private Sub CommandButton1_Click()                      
    Scan = Sheet1.Cells(5, "A").Value + 1                         
    Sheet1.Cells(5, "A").Value = Scan                             
    Sheet1.Cells(8, "A").Value = Scan + 1
    Sheet2.Cells(Scan + 4, "A").Value = Scan                      
    Sheet2.Cells(Scan + 4, "A").Value = Sheet1.Cells(19, "B")     
End Sub
answered Oct 24, 2022 by narikkadan
• 63,600 points

Related Questions In Others

0 votes
1 answer

How to automatically assign a color to the maximum and minimum values in a set of selected cells in Excel?

See Conditional Formatting, which may be accessed ...READ MORE

answered Apr 7, 2023 in Others by Kithuzzz
• 38,000 points
569 views
0 votes
1 answer

How can I store the data of an open excel workbook in a collection using BluePrism?

To do what you want is like ...READ MORE

answered Nov 24, 2022 in Others by narikkadan
• 63,600 points
1,403 views
0 votes
1 answer

Excel-How can I get the address of a cell instead of a value?

There are various difficulties in this. Which ...READ MORE

answered Dec 29, 2022 in Others by narikkadan
• 63,600 points
504 views
0 votes
1 answer

How to unmerge multiple cells and transpose each value into a new column in Pandas dataframe from excel file

Try this: df = pd.read_excel("Sample_File.xlsx", header=[0,1,2,3,4,5], index_col = ...READ MORE

answered Jan 8, 2023 in Others by narikkadan
• 63,600 points
2,594 views
0 votes
1 answer

Retrieve epay.info Balance with VBA and Excel

This code should log you in, provided ...READ MORE

answered Sep 5, 2018 in Blockchain by digger
• 26,740 points
1,260 views
0 votes
1 answer

How to load file to Excel Power query from SFTP site

Currently, I don't think there is a ...READ MORE

answered Dec 3, 2018 in Power BI by Upasana
• 8,620 points
3,697 views
0 votes
1 answer

Using VBA Excel to create a gramatically correct list

The Excel AND function is a logical ...READ MORE

answered Feb 9, 2022 in Others by gaurav
• 23,260 points
975 views
0 votes
2 answers

How to copy a formula horizontally within a table using Excel VBA?

Hi so basically, create an adjacent column ...READ MORE

answered Feb 16, 2022 in Others by Edureka
• 13,690 points
1,090 views
0 votes
1 answer

Excel - How can I get the average of cells where the value in one column is X and the value in another column is Y?

Use AVERAGEIFS ... =AVERAGEIFS(C2:C13,A2:A13,"Yellow Typ ...READ MORE

answered Nov 11, 2022 in Others by narikkadan
• 63,600 points
1,420 views
0 votes
1 answer

How can I sort one set of data to match another set of data in Excel?

In addition, INDEX MATCH is a more ...READ MORE

answered Oct 29, 2022 in Others by narikkadan
• 63,600 points
2,373 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP