create a button that do actions

kerm007

Active Member
Joined
Mar 16, 2019
Messages
266
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
 
Maybe
VBA Code:
Sub Tickets_Received()
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .ReadingOrder = xlContext
    End With
    Selection.Merge
    With Selection.Borders
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 65535
    End With
    With Selection.Font
        .ColorIndex = xlAutomatic
    End With
    ActiveCell.Value = "Received"
    Range("F29").Select
End Sub
 
Upvote 1
Solution

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
hello
no what i want is what ever line i select i want an action button that will do what the code is doing
it could be anywhere

Thanks
 
Upvote 0
@kerm007
There are 1,048,576 rows on a sheet and 16,384 columns which totals over 17 billion cells.
it could be anywhere is not very specific.

try post #10 and tell me what it isn't doing right.
 
Upvote 0
hello
yes it work should i add the code to the sheet or create a macro and then assign a button ?
Thanks
 
Upvote 0
i also notice if i do it 2 time on the same line it merge all
Thanks
 

Attachments

  • merge.png
    merge.png
    18.5 KB · Views: 8
Upvote 0
i tries again and if i select h25 to k25 it's doing it starting at F
can we do action no matter the selection i made ?
Thanks
 
Upvote 0
Maybe
VBA Code:
Sub Tickets_Received()
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .ReadingOrder = xlContext
    End With
    Selection.Merge
    With Selection.Borders
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 65535
    End With
    With Selection.Font
        .ColorIndex = xlAutomatic
    End With
    ActiveCell.Value = "Received"
    Range("F29").Select
End Sub
Hello if i run the code manually from devlopper it seems to do what i want
if i assign the code to a button it doesn't work
what im doing wrong ?
Thanks
 
Upvote 0
ok i get it need to insert the code after the button click
Thanks
 
Upvote 0
If you don't want it to return to F29, delete the 2nd last line in the code
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,195
Members
452,616
Latest member
intern444

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