how do I debug my Excel macro & make it actually WORK?
Dave,
Thanks for your post, and your insightful question.
The task is a simple "add these cells task", and usually (but not always),
I'm only adding 2 cells together in a long column of numbers. I was thinking
that if I have a group of 5 or 6 sets of 2 cells, a short loop macro will
work.
For the purposes of this macro, the cells will always be in a single column.
Thanks for the code as well. It's interesting to see how different working
code is from the examples microsoft posts.
Not to rag on MS, but sheesh! I just think they are caught up in "greek
speek", and making Visual Basic too inaccessible to the average (i.e.: dumb
like me) person. I also think they way they try to teach newbies is either
too simple or too complicated. But that's me. Of course, once you learn
something, the basic stuff seems so easy, but getting there is not easy for
me.
They don't define things well enough for me to understand what needs to be
done to make an effective macro. Their basic tutorial listed Dim as a
command, but I had to look elsewhere to learn that Dim meant Dimension!
I'll try this code and see if it serves the purpose. Oh, and I'll avoid
Ctrl-z as a macro shortcut! Again, thanks.
Mark Diaz
Boston, MA
=============================================
"Dave Peterson" wrote:
How do you know what to loop through in those 5 or 6 cells. Will they always be
the same column?
This just inserts a new row right where the active cell is. Then it puts that
formula in the cell:
Option Explicit
Sub testme()
Dim myCell As Range
Set myCell = ActiveCell
ActiveCell.EntireRow.Insert
With ActiveCell
.FormulaR1C1 = "=sum(r[-2]c:r[-1]c)"
.Font.Bold = True
End With
End Sub
ctrl-z is usually used for Edit|Undo. I'd stay away from the shortcut keys that
excel uses.
If you know the columns, this might get you closer:
Option Explicit
Sub testme()
Dim myRow As Long
ActiveCell.EntireRow.Insert
myRow = ActiveCell.Row
With ActiveSheet
With .Cells(myRow, "A")
.FormulaR1C1 = "=sum(r[-2]c:r[-1]c)"
.Font.Bold = True
End With
With .Cells(myRow, "d")
.FormulaR1C1 = "=sum(r[-2]c:r[-1]c)"
.Font.Bold = True
End With
With .Cells(myRow, "F")
.FormulaR1C1 = "=sum(r[-2]c:r[-1]c)"
.Font.Bold = True
End With
End With
End Sub
|