PC Review


Reply
Thread Tools Rate Thread

copy formula across while skipping columns

 
 
Joshua
Guest
Posts: n/a
 
      14th Feb 2009
I'm trying to write a macro that will:

1) select a range of cells within the same row - where the first cell
in the range contains a formula with a link to another cell

2)macro copies the formula from the first cell in the range and pastes
it into the remaining cells in the selected range, while skipping a
user defined number of columns

before macro:

A B C D E F G
1 10
2
3 10 20 30 40

after macro:

A B C D E F G
1 10 20 30 40
2
3 10 20 30 40

the formula in A1 is =A3. I'd like to be able to select A1:G1 and run
the macro so that C1 refers to B3, E1 refers to C3, etc. I'd like
this to also work where the formula contains a combination of one or
more links and/or arithmetic operations. Would be awesome if this
could also work vice-a-versa.

Thanks in advance for your help on this. I have absolutely no idea
how to write this kind of thing, please help! I've made my question
MUCH more concise so it should be clear now = )
 
Reply With Quote
 
 
 
 
Gary''s Student
Guest
Posts: n/a
 
      14th Feb 2009
This allows you complete control of which row, which columns and the interval.
nSkip=2 means every other column, etc.

Sub skipSome()
nRow = 3 'which row
nFirst = 7 'starting column
nLast = 39 'ending column
nSkip = 2 'interval
For i = nSkip To nLast Step nSkip
With Cells(nRow, nFirst)
.Copy .Offset(0, i)
End With
Next
End Sub

--
Gary''s Student - gsnu200833


"Joshua" wrote:

> I'm trying to write a macro that will:
>
> 1) select a range of cells within the same row - where the first cell
> in the range contains a formula with a link to another cell
>
> 2)macro copies the formula from the first cell in the range and pastes
> it into the remaining cells in the selected range, while skipping a
> user defined number of columns
>
> before macro:
>
> A B C D E F G
> 1 10
> 2
> 3 10 20 30 40
>
> after macro:
>
> A B C D E F G
> 1 10 20 30 40
> 2
> 3 10 20 30 40
>
> the formula in A1 is =A3. I'd like to be able to select A1:G1 and run
> the macro so that C1 refers to B3, E1 refers to C3, etc. I'd like
> this to also work where the formula contains a combination of one or
> more links and/or arithmetic operations. Would be awesome if this
> could also work vice-a-versa.
>
> Thanks in advance for your help on this. I have absolutely no idea
> how to write this kind of thing, please help! I've made my question
> MUCH more concise so it should be clear now = )
>

 
Reply With Quote
 
Joshua
Guest
Posts: n/a
 
      17th Feb 2009
On Feb 14, 6:19*am, Gary''s Student
<GarysStud...@discussions.microsoft.com> wrote:
> This allows you complete control of which row, which columns and the interval.
> nSkip=2 means every other column, etc.
>
> Sub skipSome()
> nRow = 3 * *'which row
> nFirst = 7 *'starting column
> nLast = 39 *'ending column
> nSkip = 2 * 'interval
> * * For i = nSkip To nLast Step nSkip
> * * With Cells(nRow, nFirst)
> * * * * .Copy .Offset(0, i)
> * * End With
> Next
> End Sub
>
> --
> Gary''s Student - gsnu200833
>
> "Joshua" wrote:
> > I'm trying to write a macro that will:

>
> > 1) select a range of cells within the same row - where the first cell
> > in the range contains a formula with a link to another cell

>
> > 2)macro copies the formula from the first cell in the range and pastes
> > it into the remaining cells in the selected range, while skipping a
> > user defined number of columns

>
> > before macro:

>
> > * *A * * * B * * * C * * * D * * * E * * * F * * * G
> > 1 *10
> > 2
> > 3 *10 * * *20 * * *30 * * *40

>
> > after macro:

>
> > * *A * * * B * * * C * * * D * * * E * * * F * * * G
> > 1 *10 * * * * * * *20 * * * * * * *30 ** * * * * *40
> > 2
> > 3 *10 * * *20 * * *30 * * *40

>
> > the formula in A1 is =A3. *I'd like to be able to select A1:G1 and run
> > the macro so that C1 refers to B3, E1 refers to C3, etc. *I'd like
> > this to also work where the formula contains a combination of one or
> > more links and/or arithmetic operations. *Would be awesome if this
> > could also work vice-a-versa.

>
> > Thanks in advance for your help on this. *I have absolutely no idea
> > how to write this kind of thing, please help! *I've made my question
> > MUCH more concise so it should be clear now = )


Thank you! this is very helpful. However, I'd like to do this by
selecting a range in the fashion I explained in my original question.
Does anyone know how to do this?

Thanks,

Joshua
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy formula across while skipping columns Joshua Microsoft Excel Programming 3 23rd Apr 2009 09:22 AM
copy across formula while skipping columns Joshua Microsoft Excel Programming 0 14th Feb 2009 06:05 AM
copy across formula while skipping columns Joshua Microsoft Excel Programming 0 14th Feb 2009 06:04 AM
Find row and insert formula, skipping columns Ray Microsoft Excel Programming 1 30th Oct 2007 01:37 PM
Copy formula with skipping rows Fewebber Microsoft Excel Worksheet Functions 0 6th Jun 2006 04:12 PM


Features
 

Advertising
 

Newsgroups
 


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