paste formula

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi,

I am trying to find a way to paste a formula into a certain column in excel
using VBA. Trying to paste the following formula:

=MONTH(I2)


The code should go to the first rown, and then paste the formula for all
rows entered.


Thanks in advance,
geebee
 
Paste is not needed. The following will enter your formula into column A in
the first 10 cells:


Sub gsnu()
Dim r As Range
Set r = Range(Cells(1, 1), Cells(10, 1))
r.Formula = "=MONTH(12)"
End Sub
 
In your case, the First Row means row 2 (headers in row 1)???

dim LastRow as long
with worksheets("sheet1")
lastrow = .cells(.rows.count,"A").end(xlup).row
.range("x2:x" & lastrow).formula = "=month(I2)"
end with

I used column A to find out the last row used--change that "A" to a column that
you know has data if the row is used.

And I put the formula in column X.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top