create a button that do actions

kerm007

Active Member
Joined
Mar 16, 2019
Messages
250
Office Version
  1. 365
Platform
  1. Windows
hello
i create a macro to merge cell , put a border, insert yellow in the cell and type a text
.
how to create a button that i can press when i need to do it for other cell i want to do this action to?
here the code

VBA Code:
Sub Tickets_Received()
'
' Tickets_Received Macro
' Merge Cell highlight and Put Text
'
' Keyboard Shortcut: Ctrl+t
'
    ActiveWindow.SmallScroll Down:=72
    Range("I88").Select
    ActiveWindow.SmallScroll Down:=-64
    Range("F28:I28").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    Selection.Merge
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 65535
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    With Selection.Font
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
    End With
    ActiveCell.FormulaR1C1 = "Received"
    Range("F29").Select
End Sub


Thanks
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
hello
is my marco is good and it will do it on any cell i select and apply macro ?
 
Upvote 0
i tries and it does only for a certain cell not the cell i select
i miss something in my code for sure maybe the range ?
Thanks
 
Upvote 0
Assuming that F28 is the cell that would have been the selected cell for the macro you've posted
change
VBA Code:
    ActiveWindow.SmallScroll Down:=72
    Range("I88").Select
    ActiveWindow.SmallScroll Down:=-64
    Range("F28:I28").Select
to
VBA Code:
    Selection.Resize(, 4).Select
 
Upvote 0
I believe the entire code could be reduced to
VBA Code:
Sub Tickets_Received()
'
' Tickets_Received Macro
' Merge Cell highlight and Put Text
'
' Keyboard Shortcut: Ctrl+t
'
    Selection.Resize(, 4).Select
    
    With Selection
        .Merge
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .BorderAround LineStyle:=xlContinuous, Weight:=xlMedium, ColorIndex:=0
        .Interior.Color = 65535
        .Value = "Recieved"
        .Offset(1).Resize(1, 1).Select
    End With
    
End Sub
 
Upvote 0
ok i will test more cause it remove the conditional formating they way it was supose to do
 
Upvote 0
should replace my code with the last one you gave me ?
Thanks
 
Upvote 0
well its doing it for line 28 but if i selects the line 65 it keep doing it for the line 28 not my sleection
Thanks
 
Upvote 0
do it for other cell i want to do this action to
You didn't actually explain what that meant
and now you're selecting line 65
so I'm just guessing that you want to be merging the same columns F to I in whatever row you have selected

VBA Code:
Sub Tickets_Received()
'
' Tickets_Received Macro
' Merge Cell highlight and Put Text

Dim rowNumber As Long
Dim rng As Range

rowNumber = Selection(1, 1).Row
Set rng = Range("F" & rowNumber).Resize(, 4)

With rng
    .Merge
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlBottom
    .BorderAround LineStyle:=xlContinuous, Weight:=xlMedium, ColorIndex:=0
    .Interior.Color = 65535
    .Value = "Recieved"
    .Offset(1).Resize(1, 1).Select
End With
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,076
Messages
6,122,984
Members
449,092
Latest member
Mr Hughes

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