Macros

  • Thread starter Christopher Anderson
  • Start date
C

Christopher Anderson

I tried recording a macro that inserts a row above the selected cell and then
puts the word count in the cell above the selected cell. I want it to happen
to whichever cell I select but when I run it, it always goes back and does it
to the cell that I originally recorded it on. Im sure it is just something I
am doing, but could some one help out???

CHris
 
D

Dave Peterson

I got this when I recorded a macro:


Christopher said:
I tried recording a macro that inserts a row above the selected cell and then
puts the word count in the cell above the selected cell. I want it to happen
to whichever cell I select but when I run it, it always goes back and does it
to the cell that I originally recorded it on. Im sure it is just something I
am doing, but could some one help out???

CHris
 
D

Dave Peterson

I got this when I recorded a macro:

Option Explicit
Sub Macro1()
Rows("12:12").Select
Selection.Insert Shift:=xlDown
Range("A12").Select
ActiveCell.FormulaR1C1 = "Count"
End Sub

I could generalize it to this:

Option Explicit
Sub Macro1A()
Dim myCell As Range
Set myCell = ActiveCell

With myCell
.EntireRow.Insert
.Offset(-1, 0).Value = "Count"
End With
End Sub
 
H

h317

Sub ThisMacro()
With Selection
.EntireRow.Insert
.Cells(0, 1).Value = "Count"
End With
End Sub

Hope it helps.
 
Top