Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default paste formula

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default paste formula

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
--
Gary''s Student


"geebee" wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default paste formula

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.


geebee wrote:

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


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel formula to copy/paste formula needed please. colwyn Excel Discussion (Misc queries) 4 October 22nd 08 11:27 PM
Paste value from a formula AMH Excel Worksheet Functions 2 January 29th 08 04:31 PM
Paste formula every nth row edinclimb Excel Discussion (Misc queries) 1 January 2nd 06 11:52 PM
formula cut and paste Bryan J Bloom Excel Worksheet Functions 3 November 3rd 05 01:38 PM
Paste Formula andibevan Excel Programming 0 November 11th 04 03:38 PM


All times are GMT +1. The time now is 10:59 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"