Push button function

Eddy86

New Member
Joined
Mar 1, 2022
Messages
4
Platform
  1. Windows
Hi All

Been searching for an asnwer, with no luck unfortunately.
Let's say I want to change the border colour of a specific merged cell when I click on a 'push button'.

Ie, regarding the attached snippet. If I click on the merged cell St Ives (5 days), then click on the button in the top left corner, I want the St Ives (5 days) cell border to change red.

Any help with be appreciated.
Noob.
 

Attachments

  • Excel snippet.PNG
    Excel snippet.PNG
    10.4 KB · Views: 7

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi. First, I would strongly advise against using merged cells. I have never encountered a good reason to use them, and in my experience, they seem to always result in headaches. That said, in answer to your question, I'd recommend using the Macro Recorder - it will monitor your actions and then produce code for you that you can use. It's a bit of an artform, to be honest, but it is a useful skill. I used it just now to come up with the the following routine you wanted - namely, that it will draw a red border around the selected cells:

VBA Code:
Sub AddRedBorder()
    Dim Target      As Range
    Dim SideBorder  As Long
    
    Set Target = Selection
    For SideBorder = 7 To 10
        With Target.Borders(SideBorder)
            .LineStyle = xlContinuous
            .Color = vbRed
            .Weight = xlMedium
        End With
    Next
End Sub

I actually edited that a bit, because the raw code is usually a lot more verbose, but you get my point. There are plenty of guides online on how to use it. Here is an introduction from Microsoft.
 
Upvote 0
Solution
Excatly what I was after, created 4 button functions with editing the code slightly. Thanks!
 
Upvote 0

Forum statistics

Threads
1,213,550
Messages
6,114,265
Members
448,558
Latest member
aivin

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