Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
Put data in range of selected cells
I use a spreadsheet for duty rostas at work and have macros to enter codes
into a range of selected cells for various things like annual leave (H) sickness (Y, S or F depending on certificate), maternity leave (M). I currently merge the selected cells. Here is an example of my macros. Sub CodeM() Application.Run "White" Application.Run "CellsMerge" ActiveCell.FormulaR1C1 = "M" End Sub Sub White() ActiveCell.Font.Name = "Arial" Selection.Font.FontStyle = "Bold" Selection.Font.Size = 9 ColourCellWhite (0) NoArrows (0) End Sub Sub CellsMerge() With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlTop .WrapText = True .Orientation = 0 .AddIndent = False .ShrinkToFit = False .MergeCells = True End With End Sub However, I don't really want the cells merged and would prefer the macro 'CodeM' (and other similar macros I have) to work through each highlighted cell when the user clicks the button to run it and put the code in each one. How do I get the macro to move through the selected cells, or put the same code in all of them. Many thanks. |
#2
Posted to microsoft.public.excel.misc
|
|||
|
|||
Put data in range of selected cells
You could use something like this:
Sub SetEm() Dim cell As Range For Each cell In Selection SetBold cell Next cell End Sub Sub SetBold(c As Range) With c .Font.Bold = True End With End Sub "MusicMaker" wrote in message ... I use a spreadsheet for duty rostas at work and have macros to enter codes into a range of selected cells for various things like annual leave (H) sickness (Y, S or F depending on certificate), maternity leave (M). I currently merge the selected cells. Here is an example of my macros. Sub CodeM() Application.Run "White" Application.Run "CellsMerge" ActiveCell.FormulaR1C1 = "M" End Sub Sub White() ActiveCell.Font.Name = "Arial" Selection.Font.FontStyle = "Bold" Selection.Font.Size = 9 ColourCellWhite (0) NoArrows (0) End Sub Sub CellsMerge() With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlTop .WrapText = True .Orientation = 0 .AddIndent = False .ShrinkToFit = False .MergeCells = True End With End Sub However, I don't really want the cells merged and would prefer the macro 'CodeM' (and other similar macros I have) to work through each highlighted cell when the user clicks the button to run it and put the code in each one. How do I get the macro to move through the selected cells, or put the same code in all of them. Many thanks. |
#3
Posted to microsoft.public.excel.misc
|
|||
|
|||
Put data in range of selected cells
Thanks Zone. I adapted your code for my use and it worked a treat.
Many thanks. "Zone" wrote: You could use something like this: Sub SetEm() Dim cell As Range For Each cell In Selection SetBold cell Next cell End Sub Sub SetBold(c As Range) With c .Font.Bold = True End With End Sub "MusicMaker" wrote in message ... I use a spreadsheet for duty rostas at work and have macros to enter codes into a range of selected cells for various things like annual leave (H) sickness (Y, S or F depending on certificate), maternity leave (M). I currently merge the selected cells. Here is an example of my macros. Sub CodeM() Application.Run "White" Application.Run "CellsMerge" ActiveCell.FormulaR1C1 = "M" End Sub Sub White() ActiveCell.Font.Name = "Arial" Selection.Font.FontStyle = "Bold" Selection.Font.Size = 9 ColourCellWhite (0) NoArrows (0) End Sub Sub CellsMerge() With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlTop .WrapText = True .Orientation = 0 .AddIndent = False .ShrinkToFit = False .MergeCells = True End With End Sub However, I don't really want the cells merged and would prefer the macro 'CodeM' (and other similar macros I have) to work through each highlighted cell when the user clicks the button to run it and put the code in each one. How do I get the macro to move through the selected cells, or put the same code in all of them. Many thanks. |
#4
Posted to microsoft.public.excel.misc
|
|||
|
|||
Put data in range of selected cells
You're welcome! Thanks for the feedback. James
"MusicMaker" wrote in message ... Thanks Zone. I adapted your code for my use and it worked a treat. Many thanks. "Zone" wrote: You could use something like this: Sub SetEm() Dim cell As Range For Each cell In Selection SetBold cell Next cell End Sub Sub SetBold(c As Range) With c .Font.Bold = True End With End Sub "MusicMaker" wrote in message ... I use a spreadsheet for duty rostas at work and have macros to enter codes into a range of selected cells for various things like annual leave (H) sickness (Y, S or F depending on certificate), maternity leave (M). I currently merge the selected cells. Here is an example of my macros. Sub CodeM() Application.Run "White" Application.Run "CellsMerge" ActiveCell.FormulaR1C1 = "M" End Sub Sub White() ActiveCell.Font.Name = "Arial" Selection.Font.FontStyle = "Bold" Selection.Font.Size = 9 ColourCellWhite (0) NoArrows (0) End Sub Sub CellsMerge() With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlTop .WrapText = True .Orientation = 0 .AddIndent = False .ShrinkToFit = False .MergeCells = True End With End Sub However, I don't really want the cells merged and would prefer the macro 'CodeM' (and other similar macros I have) to work through each highlighted cell when the user clicks the button to run it and put the code in each one. How do I get the macro to move through the selected cells, or put the same code in all of them. Many thanks. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Average Selected Cells From a Range | Excel Worksheet Functions | |||
data validation list selected from a range | Excel Discussion (Misc queries) | |||
How can i put a negative sign on a range of selected cells? | Excel Discussion (Misc queries) | |||
Automatically clear values from a range of selected cells | Excel Discussion (Misc queries) | |||
How do I merge in a selected range of cells out of Excel? | Excel Discussion (Misc queries) |