Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Copy paste formula up to a cell using VBA

Hello all

I have a little problem and i need help

I have two worksheets. In the first one i manually add historic data (every
time different size).
In the second one I have formulas based on the historic data.
I want to add the formula only in the first row and then using a button to
copy paste
the formulas up to the cell that the historic data ends. I used this code
but the problem is that
i do not know how to define B? which every time will be different one

Range("A1:B1").Select
Selection.AutoFill Destination:=Range("A2:B?"), Type:=xlFillDefault
Range("A2:B?").Select
Range("A1").Select

A1 and B1 contains the formulas
So if for example in Sheet1 i have historic data from A1-A500 (the size
varies )
I want formulas in Sheet 2 to be calculated up to cell B500

I am really stuck with this one.

Thanks in advance

AngelikiS


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Copy paste formula up to a cell using VBA

Can you pick out a column that always has data in it?

If yes, then I'd use something like:

Option Explicit
Sub test()
Dim LastRow As Long
With ActiveSheet
LastRow = .Cells(.Rows.Count, "E").End(xlUp).Row
.Range("a1:b1").AutoFill _
Destination:=.Range("a1:b" & LastRow), Type:=xlFillDefault
End With
End Sub

If you can't rely on a column, you might be able to use
..specialcells(xlcelltypelastcell). But excel keeps track of that a lot better
than most humans. You might be underestimating where ctrl-End takes you.

Option Explicit
Sub test()
Dim LastRow As Long
Dim dummyRng As Range
With ActiveSheet
Set dummyRng = .UsedRange
LastRow = .Cells.SpecialCells(xlcelltyplastcell).Row
.Range("a1:b1").AutoFill _
Destination:=.Range("a1:b" & LastRow), Type:=xlFillDefault
End With
End Sub

sometimes using .usedrange will reset that lastused cell to what you expect.



Angeliki wrote:

Hello all

I have a little problem and i need help

I have two worksheets. In the first one i manually add historic data (every
time different size).
In the second one I have formulas based on the historic data.
I want to add the formula only in the first row and then using a button to
copy paste
the formulas up to the cell that the historic data ends. I used this code
but the problem is that
i do not know how to define B? which every time will be different one

Range("A1:B1").Select
Selection.AutoFill Destination:=Range("A2:B?"), Type:=xlFillDefault
Range("A2:B?").Select
Range("A1").Select

A1 and B1 contains the formulas
So if for example in Sheet1 i have historic data from A1-A500 (the size
varies )
I want formulas in Sheet 2 to be calculated up to cell B500

I am really stuck with this one.

Thanks in advance

AngelikiS


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Copy paste formula up to a cell using VBA

typo alret!

xlCellTypeLastCell is misspelled in the second sub.


LastRow = .Cells.SpecialCells(xlcelltyplastcell).Row


<<Snipped
--

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
Copy/Paste Formula-dropping 1st cell address kesitton Excel Discussion (Misc queries) 1 March 30th 10 08:30 PM
Write formula for simple copy and paste to another cell Kalffiend Excel Worksheet Functions 1 January 12th 10 09:10 PM
Copy and paste a formula in a locked cell nsnyder Excel Discussion (Misc queries) 1 July 21st 09 06:06 PM
Repeat Cell Formula w/out copy/paste? DTTODGG Excel Discussion (Misc queries) 1 March 13th 06 05:11 PM
How do I copy a formula/paste w/o losing the cell content? CShannon Excel Discussion (Misc queries) 6 June 25th 05 12:39 PM


All times are GMT +1. The time now is 12:15 PM.

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

About Us

"It's about Microsoft Excel"