Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 118
Default Copy formula - Tom Ogilvy

Sub CopyFormulas()
Dim rng1 as Range, rng2 as Range, i as Long
on Error Resume Next
set rng1 = Application.InputBox("Select cells to copy using
mouse",type:=8)
On Error goto 0
if rng1 is nothing then
msgbox "You selected nothing"
exit sub
end if

on Error Resume Next
set rng2 = Application.InputBox("Select top cell to paste tousing
mouse",type:=8)
On Error goto 0
if rng2 is nothing then
msgbox "You selected nothing"
exit sub
end if

i = 1
for each cell in rng1
rng2(i).Formula = cell.formula
i = i + 1
Next

End Sub


Coulp Tom or someone else make the above formula work for both a
vertical & horizontal range.As it's now pasting range vertically even
if a horizontal range has been copied.

Thxs a lot

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Copy formula - Tom Ogilvy

Replace

i = 1
for each cell in rng1
rng2(i).Formula = cell.formula
i = i + 1
Next

with

i = 1
For Each cell In rng1
If rng1.Columns.Count = 1 Then
rng2(i).Formula = cell.Formula
Else
rng2(, i).Formula = cell.Formula
End If
i = i + 1
Next


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"al007" wrote in message
ups.com...
Sub CopyFormulas()
Dim rng1 as Range, rng2 as Range, i as Long
on Error Resume Next
set rng1 = Application.InputBox("Select cells to copy using
mouse",type:=8)
On Error goto 0
if rng1 is nothing then
msgbox "You selected nothing"
exit sub
end if

on Error Resume Next
set rng2 = Application.InputBox("Select top cell to paste
tousing
mouse",type:=8)
On Error goto 0
if rng2 is nothing then
msgbox "You selected nothing"
exit sub
end if

i = 1
for each cell in rng1
rng2(i).Formula = cell.formula
i = i + 1
Next

End Sub


Coulp Tom or someone else make the above formula work for both
a
vertical & horizontal range.As it's now pasting range
vertically even
if a horizontal range has been copied.

Thxs a lot



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 118
Default Copy formula - Tom Ogilvy

Chip,
Thxs a lot ! - am a great fan of yours as I've been learning a lot from
your site.
Pls keep adding new tips




Chip Pearson wrote:
Replace

i = 1
for each cell in rng1
rng2(i).Formula = cell.formula
i = i + 1
Next

with

i = 1
For Each cell In rng1
If rng1.Columns.Count = 1 Then
rng2(i).Formula = cell.Formula
Else
rng2(, i).Formula = cell.Formula
End If
i = i + 1
Next


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"al007" wrote in message
ups.com...
Sub CopyFormulas()
Dim rng1 as Range, rng2 as Range, i as Long
on Error Resume Next
set rng1 = Application.InputBox("Select cells to copy using
mouse",type:=8)
On Error goto 0
if rng1 is nothing then
msgbox "You selected nothing"
exit sub
end if

on Error Resume Next
set rng2 = Application.InputBox("Select top cell to paste
tousing
mouse",type:=8)
On Error goto 0
if rng2 is nothing then
msgbox "You selected nothing"
exit sub
end if

i = 1
for each cell in rng1
rng2(i).Formula = cell.formula
i = i + 1
Next

End Sub


Coulp Tom or someone else make the above formula work for both
a
vertical & horizontal range.As it's now pasting range
vertically even
if a horizontal range has been copied.

Thxs a lot


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
Tom Ogilvy - More help please Tempy Excel Programming 4 May 20th 05 07:20 AM
Tom Ogilvy halem2[_26_] Excel Programming 4 September 17th 04 03:26 PM
Thank u Tom Ogilvy helmekki[_19_] Excel Programming 0 August 7th 04 04:31 PM
Tom Ogilvy David Joseph Excel Programming 0 April 21st 04 02:57 PM
For Tom Ogilvy re Copy Sheet Problem Jim[_34_] Excel Programming 1 January 3rd 04 02:41 PM


All times are GMT +1. The time now is 05:53 AM.

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"