Copying the same Macro to multiple rows

neild1973

New Member
Joined
Aug 6, 2010
Messages
7
Hi, Newbie here so hope this isn't a stupid question. I have created my first Macro which provides a tick box and when pressed places a "Y" in all the 5 cells to the left. I would now like to replicate this macro in the following 100 or so rows below but other than recording 100 macro's I am lost. Please help.
The code that the macro has produced is posted below.
Sub Macro1()
'
' Macro1 Macro
'
'
Range("H10").Select
ActiveCell.FormulaR1C1 = "y"
With ActiveCell.Characters(Start:=1, Length:=1).Font
.Name = "Times New Roman"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
Range("G10").Select
ActiveCell.FormulaR1C1 = "y"
With ActiveCell.Characters(Start:=1, Length:=1).Font
.Name = "Times New Roman"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
Range("F10").Select
ActiveCell.FormulaR1C1 = "y"
With ActiveCell.Characters(Start:=1, Length:=1).Font
.Name = "Times New Roman"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
Range("E10").Select
ActiveCell.FormulaR1C1 = "y"
With ActiveCell.Characters(Start:=1, Length:=1).Font
.Name = "Times New Roman"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
Range("D10").Select
ActiveCell.FormulaR1C1 = "y"
With ActiveCell.Characters(Start:=1, Length:=1).Font
.Name = "Times New Roman"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
Range("C10").Select
End Sub
<!-- / message --><!-- BEGIN TEMPLATE: ad_showthread_firstpost_sig --><!-- END TEMPLATE: ad_showthread_firstpost_sig -->
<!-- controls -->
progress.gif
 
Hi VOG,

Thanks for the post, unfortunately this just inserted a "Y" one cell to the right of the Form Control box?

Can I upload the Spreadsheet? thought it may help?
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Sorry That's not strictly correct, it inserts the "Y" in the last cell clicked on previous to clicking on the Form Control Button?
 
Upvote 0
You need to select the cells first. Click in the first cell then hold down the CTRL button and click to select other cells. Then run the macro.
 
Upvote 0
Maybe not of use if you already have the controls in the sheet, but I would consider something like

Code:
Private Sub worksheet_beforedoubleclick(ByVal target As Range, cancel As Boolean)
If target.Column = 7 Then '(7 = column G)
cancel = 1
With Range(ActiveCell.Offset(0, -5), ActiveCell.Offset(0, -1))
.Value = "y"
.Font.Name = "Times New Roman"
.Font.Size = 10
End With
With ActiveCell
.Value = "a"
.Font.Name = "Webdings"
.Font.Size = 12
End With
End If
End Sub

Copied into the worksheet module.

The code is set up for the "All" column as column G, it works by double clicking the cell.
 
Upvote 0
Jasonb75,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p></o:p>
You are a legend, works perfectly.<o:p></o:p>
<o:p> </o:p>
Many Thanks<o:p></o:p>
Neil<o:p></o:p>
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,692
Members
448,979
Latest member
DET4492

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