Using a command button to update a cell value

Adrian1

Board Regular
Joined
Dec 30, 2003
Messages
126
Hi you clever people,

Could someone please tell me how I would make a command button do the following:

Make the value of merged cells b7:d7 equal the value of merged cells b6:d6 plus one?

When pressed, I want the button to populate cell range b7:d7 with the value plus one in (merged cells) b6:d6.

I hope this makes sense. :rolleyes:
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
First, name the merged cells - each one gets a range name.
Then create a VBA macro with the statement Range(name2).value = Range(name1).value + 1.
Create your button, right-click on it and assign the macro.
 
Upvote 0
Okay, my cell range b6:d6 is now named index1
my cell range b7:d7 is now named index2

I have created a command button which has the following code

Private Sub CommandButton5_Click()
Range("index2").Value = Range("index1").Value + 1
End Sub

Why does this not work? I keep getting a runtime error
 
Upvote 0
If you're using Excel 97, altough I don't know if it would affect in this case, try setting the 'SetFocusOnClick' property of the button to False.
 
Upvote 0
This worked fine for me. Check to be sure your names are there. Press F5 on your sheet and see if they appear.
 
Upvote 0
I have tried all of your suggestions but still it wont work. It must be something and nothing that is causing the problem.

Private Sub CommandButton5_Click()

Range("index2").Value = Range("index1").Value + 1

End Sub

Why would this give me a type mismatch error? Now I am really scratching my head. :cry:
 
Upvote 0
Put this in the inmediate window in VBE, and copy the results here:

?IsNumeric(Range("index1").Value), IsNumeric(Range("index2").Value), Range("index1").Value, Range("index2").Value
 
Upvote 0
Juan,

Sorry, I am not sure what you mean there. Sorry, I know it is frustrating. Instead of naming the cell range, I applied it to single cell references.....

Range("d9").Value = Range("d10").Value + 1

...this works fine. I just seem to have problems when I apply the same to named cell ranges. What could it be. I didn't understand the last thing you asked me to do...sorry :rolleyes:
 
Upvote 0
Check to be sure that the name you added references the cell or merged cell correctly. Sounds like you may have not clicked on your cell when adding the name and so the macro is referencing a blank cell????
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,387
Members
448,956
Latest member
JPav

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