PC Review


Reply
Thread Tools Rate Thread

copying down a formula only where there is data

 
 
childofthe1980s
Guest
Posts: n/a
 
      14th Jul 2009
Hello:

I created a macro that calculates, within a column, percentages based on
data in the columns to the immediate left.

The only issue with this macro is that the column is only copied "down" 604
rows in the spreadsheet. I can modify the macro in VBA to copy straight down
to the last row possible in Excel. But, I would prefer to have it copied
down to the last row that contains data to the immediate left of the column.
(This column is column L and is the last column in my spreadsheet.)

Here is the code that does this copying:

Selection.AutoFill Destination:=Range("L2:L604")
Range("L2:L604").Select

How can I (a) modify the code to just copy down to that last row of data and
(b) save this modfication in VBA so that I can re-use the .xlt file?

Thanks!

childofthe1980s
 
Reply With Quote
 
 
 
 
Jim Thomlinson
Guest
Posts: n/a
 
      14th Jul 2009
Selection.AutoFill Destination:=Range(range("L2"), cells(rows.count,
"L").end(xlup))
Range(range("L2"), cells(rows.count, "L").end(xlup)).select
--
HTH...

Jim Thomlinson


"childofthe1980s" wrote:

> Hello:
>
> I created a macro that calculates, within a column, percentages based on
> data in the columns to the immediate left.
>
> The only issue with this macro is that the column is only copied "down" 604
> rows in the spreadsheet. I can modify the macro in VBA to copy straight down
> to the last row possible in Excel. But, I would prefer to have it copied
> down to the last row that contains data to the immediate left of the column.
> (This column is column L and is the last column in my spreadsheet.)
>
> Here is the code that does this copying:
>
> Selection.AutoFill Destination:=Range("L2:L604")
> Range("L2:L604").Select
>
> How can I (a) modify the code to just copy down to that last row of data and
> (b) save this modfication in VBA so that I can re-use the .xlt file?
>
> Thanks!
>
> childofthe1980s

 
Reply With Quote
 
childofthe1980s
Guest
Posts: n/a
 
      15th Jul 2009
Hmm....I got a debugger error on that first line when I used that
programming...please help.

Here's the full program including those two lines that you suggested:

ActiveWindow.LargeScroll ToRight:=1
ActiveWindow.SmallScroll ToRight:=-5
Range("L2").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-2]<RC[-5], RC[-2]/RC[-5], 0)"
Range("L2").Select
Selection.AutoFill Destination:=Range(Range("L2"), Cells(Rows.Count,
"L").End(xlUp))
Range(Range("L2"), Cells(Rows.Count, "L").End(xlUp)).Select
Columns("L:L").Select
Selection.NumberFormat = "0%"
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Range(Range("L2"), Cells(Rows.Count, "L").End(xlUp)).Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "% Below Min"
Range("L3").Select
Columns("L:L").EntireColumn.AutoFit
ActiveWindow.LargeScroll ToRight:=-1
Range("A1").Select
End Sub


"Jim Thomlinson" wrote:

> Selection.AutoFill Destination:=Range(range("L2"), cells(rows.count,
> "L").end(xlup))
> Range(range("L2"), cells(rows.count, "L").end(xlup)).select
> --
> HTH...
>
> Jim Thomlinson
>
>
> "childofthe1980s" wrote:
>
> > Hello:
> >
> > I created a macro that calculates, within a column, percentages based on
> > data in the columns to the immediate left.
> >
> > The only issue with this macro is that the column is only copied "down" 604
> > rows in the spreadsheet. I can modify the macro in VBA to copy straight down
> > to the last row possible in Excel. But, I would prefer to have it copied
> > down to the last row that contains data to the immediate left of the column.
> > (This column is column L and is the last column in my spreadsheet.)
> >
> > Here is the code that does this copying:
> >
> > Selection.AutoFill Destination:=Range("L2:L604")
> > Range("L2:L604").Select
> >
> > How can I (a) modify the code to just copy down to that last row of data and
> > (b) save this modfication in VBA so that I can re-use the .xlt file?
> >
> > Thanks!
> >
> > childofthe1980s

 
Reply With Quote
 
childofthe1980s
Guest
Posts: n/a
 
      15th Jul 2009
Actually, here is the solution:

ActiveWindow.LargeScroll ToRight:=1
ActiveWindow.SmallScroll ToRight:=-5
Range("L2:L" & Cells(Cells.Rows.Count, "J").End(xlUp).Row).FormulaR1C1 =
"=IF(RC[-2]<RC[-5], RC[-2]/RC[-5], 0)"
Columns("L:L").NumberFormat = "0%"
Range("L2:L" & Cells(Cells.Rows.Count, "J").End(xlUp).Row).Value =
Range("L2:L" & Cells(Cells.Rows.Count, "J").End(xlUp).Row).Value
Range("L1").Value = "% Below Min"
Application.CutCopyMode = False
Columns("L:L").EntireColumn.AutoFit
ActiveWindow.LargeScroll ToRight:=-1
Range("A1").Select




"Jim Thomlinson" wrote:

> Selection.AutoFill Destination:=Range(range("L2"), cells(rows.count,
> "L").end(xlup))
> Range(range("L2"), cells(rows.count, "L").end(xlup)).select
> --
> HTH...
>
> Jim Thomlinson
>
>
> "childofthe1980s" wrote:
>
> > Hello:
> >
> > I created a macro that calculates, within a column, percentages based on
> > data in the columns to the immediate left.
> >
> > The only issue with this macro is that the column is only copied "down" 604
> > rows in the spreadsheet. I can modify the macro in VBA to copy straight down
> > to the last row possible in Excel. But, I would prefer to have it copied
> > down to the last row that contains data to the immediate left of the column.
> > (This column is column L and is the last column in my spreadsheet.)
> >
> > Here is the code that does this copying:
> >
> > Selection.AutoFill Destination:=Range("L2:L604")
> > Range("L2:L604").Select
> >
> > How can I (a) modify the code to just copy down to that last row of data and
> > (b) save this modfication in VBA so that I can re-use the .xlt file?
> >
> > Thanks!
> >
> > 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
copying down the formula just for data childofthe1980s Microsoft Excel Programming 3 23rd Jun 2009 06:15 PM
RE: copying down the formula just for data Mike H Microsoft Excel Programming 0 23rd Jun 2009 05:57 PM
Copying Data/Formula Kristi Microsoft Excel Worksheet Functions 1 27th Nov 2007 08:58 PM
formula copying data and lay out Kootje Microsoft Excel Misc 6 30th Jun 2006 04:43 PM
copying data by way of a formula =?Utf-8?B?U2FuZHk=?= Microsoft Excel Worksheet Functions 2 7th Apr 2004 04:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:55 AM.