PC Review


Reply
Thread Tools Rate Thread

copying rows to all possible records during a macro

 
 
childofthe1980s
Guest
Posts: n/a
 
      22nd Apr 2008
Hello:

I have created a macro that, among other things, copies a formula from the
first row of records to the remaining rows of records in the spreadsheet of
data that I exported to Excel from an accounting application.

Now, is there a way (perhaps in VBA Editor) that I can tell the macro to
copy this formula to any and all possible records that are exported to Excel?
I can see where, if there are more or less records exported during the next
export, that some of the programming can be "lost".

childofthe1980s
 
Reply With Quote
 
 
 
 
akphidelt
Guest
Posts: n/a
 
      22nd Apr 2008
When it comes to dynamic ranges like this I usually get a count of the number
of rows and then paste the formula down to that row... for example

Dim x as Integer

x = Range("A1").End(xlDown).Row

Range("B1").Formula = "Yourformula"
Range("B1").Copy
Range("B2:B" & x).PasteSpecial


"childofthe1980s" wrote:

> Hello:
>
> I have created a macro that, among other things, copies a formula from the
> first row of records to the remaining rows of records in the spreadsheet of
> data that I exported to Excel from an accounting application.
>
> Now, is there a way (perhaps in VBA Editor) that I can tell the macro to
> copy this formula to any and all possible records that are exported to Excel?
> I can see where, if there are more or less records exported during the next
> export, that some of the programming can be "lost".
>
> childofthe1980s

 
Reply With Quote
 
childofthe1980s
Guest
Posts: n/a
 
      22nd Apr 2008
Yeah, but the number of rows could be any amount. Is there a way to
dynamically program this into VBA? I already pasted the formulas down to
3231 rows. What if, next time, it's 3232 rows?

childofthe1980s

"akphidelt" wrote:

> When it comes to dynamic ranges like this I usually get a count of the number
> of rows and then paste the formula down to that row... for example
>
> Dim x as Integer
>
> x = Range("A1").End(xlDown).Row
>
> Range("B1").Formula = "Yourformula"
> Range("B1").Copy
> Range("B2:B" & x).PasteSpecial
>
>
> "childofthe1980s" wrote:
>
> > Hello:
> >
> > I have created a macro that, among other things, copies a formula from the
> > first row of records to the remaining rows of records in the spreadsheet of
> > data that I exported to Excel from an accounting application.
> >
> > Now, is there a way (perhaps in VBA Editor) that I can tell the macro to
> > copy this formula to any and all possible records that are exported to Excel?
> > I can see where, if there are more or less records exported during the next
> > export, that some of the programming can be "lost".
> >
> > childofthe1980s

 
Reply With Quote
 
akphidelt
Guest
Posts: n/a
 
      22nd Apr 2008
Every time you run the macro

Range("A1").End(xlDown).Row will regenerate

So no matter how many rows you have it will start from A1 and count all the
way til it reaches a blank cell. So it would matter if you had 5 or 50000.

The

Range("B2:B" & x)

Basically is the same thing as something like Range("B2:B3231")
Except x is a variable and dependent on how many rows of data there are.

"childofthe1980s" wrote:

> Yeah, but the number of rows could be any amount. Is there a way to
> dynamically program this into VBA? I already pasted the formulas down to
> 3231 rows. What if, next time, it's 3232 rows?
>
> childofthe1980s
>
> "akphidelt" wrote:
>
> > When it comes to dynamic ranges like this I usually get a count of the number
> > of rows and then paste the formula down to that row... for example
> >
> > Dim x as Integer
> >
> > x = Range("A1").End(xlDown).Row
> >
> > Range("B1").Formula = "Yourformula"
> > Range("B1").Copy
> > Range("B2:B" & x).PasteSpecial
> >
> >
> > "childofthe1980s" wrote:
> >
> > > Hello:
> > >
> > > I have created a macro that, among other things, copies a formula from the
> > > first row of records to the remaining rows of records in the spreadsheet of
> > > data that I exported to Excel from an accounting application.
> > >
> > > Now, is there a way (perhaps in VBA Editor) that I can tell the macro to
> > > copy this formula to any and all possible records that are exported to Excel?
> > > I can see where, if there are more or less records exported during the next
> > > export, that some of the programming can be "lost".
> > >
> > > childofthe1980s

 
Reply With Quote
 
childofthe1980s
Guest
Posts: n/a
 
      22nd Apr 2008
Thank you!!!!

childofthe1980s

"akphidelt" wrote:

> Every time you run the macro
>
> Range("A1").End(xlDown).Row will regenerate
>
> So no matter how many rows you have it will start from A1 and count all the
> way til it reaches a blank cell. So it would matter if you had 5 or 50000.
>
> The
>
> Range("B2:B" & x)
>
> Basically is the same thing as something like Range("B2:B3231")
> Except x is a variable and dependent on how many rows of data there are.
>
> "childofthe1980s" wrote:
>
> > Yeah, but the number of rows could be any amount. Is there a way to
> > dynamically program this into VBA? I already pasted the formulas down to
> > 3231 rows. What if, next time, it's 3232 rows?
> >
> > childofthe1980s
> >
> > "akphidelt" wrote:
> >
> > > When it comes to dynamic ranges like this I usually get a count of the number
> > > of rows and then paste the formula down to that row... for example
> > >
> > > Dim x as Integer
> > >
> > > x = Range("A1").End(xlDown).Row
> > >
> > > Range("B1").Formula = "Yourformula"
> > > Range("B1").Copy
> > > Range("B2:B" & x).PasteSpecial
> > >
> > >
> > > "childofthe1980s" wrote:
> > >
> > > > Hello:
> > > >
> > > > I have created a macro that, among other things, copies a formula from the
> > > > first row of records to the remaining rows of records in the spreadsheet of
> > > > data that I exported to Excel from an accounting application.
> > > >
> > > > Now, is there a way (perhaps in VBA Editor) that I can tell the macro to
> > > > copy this formula to any and all possible records that are exported to Excel?
> > > > I can see where, if there are more or less records exported during the next
> > > > export, that some of the programming can be "lost".
> > > >
> > > > childofthe1980s

 
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
macro: Copying to all possible rows childofthe1980s Microsoft Excel Programming 5 23rd Apr 2008 10:27 PM
Macro: Copying to all possible rows childofthe1980s Microsoft Excel Programming 2 23rd Apr 2008 06:30 PM
Macro for copying a value to a variable no. of rows Ian Grega Microsoft Excel Misc 6 15th Apr 2008 02:48 PM
copying rows using macro ashishprem Microsoft Excel Programming 2 13th Feb 2006 01:02 PM
Help Please - VBA Macro- Copying rows to new file Uziel Microsoft Excel Programming 2 13th Sep 2004 01:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:32 AM.