running macro to the last line

struf

Board Regular
Joined
Jul 2, 2002
Messages
107
I have a macro which I recorded that has a calculation in column E, based on the information in the previous rows.
when i recorded the original, i had the formula in E1:E100.
when i import new information, and only import 70 lines, i get 30 lines of #N/A that i need to clear, or if i import 110 lines, i need to copy my formula down the final 10 rows.
is there a way i can change the formula to continue / stop calculating when there is no more information to do so??
seems to me i saw this somewhere during my browsing of this site, but can not seem to find it.
many thanks in advance.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
ChDir "D:GARY"
Workbooks.OpenText Filename:="D:GARYIGX.DAT", Origin:=xlWindows, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False, Comma:=False _
, Space:=False, Other:=True, OtherChar:="`", FieldInfo:=Array(Array(1, 1 _
), Array(2, 2), Array(3, 2), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 2), Array(8, 1), _
Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1), Array(14, 1))
Columns("J:J").Select
Selection.Insert Shift:=xlToRight
ActiveWindow.Zoom = 75
Rows("1:1").Select
Selection.Insert Shift:=xlDown
Range("A1").Select
ActiveCell.FormulaR1C1 = "FR"
Range("B1").Select
ActiveCell.FormulaR1C1 = "REGION"
Range("C1").Select
ActiveCell.FormulaR1C1 = "CUSTOMER"
Range("D1").Select
ActiveCell.FormulaR1C1 = "NAME"
Range("E1").Select
ActiveCell.FormulaR1C1 = "ADDRESS"
Range("F1").Select
ActiveCell.FormulaR1C1 = "ENT-BY"
Range("G1").Select
ActiveCell.FormulaR1C1 = "SO"
Range("H1").Select
ActiveCell.FormulaR1C1 = "SLS"
Range("I1").Select
ActiveCell.FormulaR1C1 = "CST"
Range("J1").Select
ActiveCell.FormulaR1C1 = "MARGIN"
Range("K1").Select
ActiveCell.FormulaR1C1 = "ST"
Range("L1").Select
ActiveCell.FormulaR1C1 = "DEPT-CD"
Range("M1").Select
ActiveCell.FormulaR1C1 = "DATE"
Range("N1").Select
ActiveCell.FormulaR1C1 = "REP"
Range("O1").Select
ActiveCell.FormulaR1C1 = "REP NAME"
Columns("O:O").Select
Columns("O:O").EntireColumn.AutoFit
Columns("N:N").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = False
End With
Rows("1:1").Select
Range("C1").Activate
Selection.Font.Bold = True
Selection.Font.Underline = xlUnderlineStyleSingle
Columns("H:I").Select
Selection.Style = "Comma"
Range("J2").Select
ActiveCell.FormulaR1C1 = "=1-(RC[-1]/RC[-2])"
Range("J2").Select
Selection.Style = "Percent"
Selection.NumberFormat = "0.0%"
Selection.AutoFill Destination:=Range("J2:J67"), Type:=xlFillDefault
Range("J2:J67").Select
Columns("A:M").Select
Columns("A:M").EntireColumn.AutoFit
ActiveWindow.SmallScroll ToRight:=5
Columns("N:O").Select
Columns("N:O").EntireColumn.AutoFit
Range("A1").Select
 
Upvote 0
I don't see any formulas in E1:E100. But I do see formulas in J2:J67.

Try changing:

Code:
Selection.AutoFill Destination:=Range("J2:J67"), Type:=xlFillDefault 
Range("J2:J67").Select

to:

Code:
Range("J2:J" & Range("J65536").End(xlUp).Row).Clear
Selection.AutoFill Destination:=Range("J2:J" & Range("A65536").End(xlUp).Row)), Type:=xlFillDefault
 
Upvote 0

Forum statistics

Threads
1,213,504
Messages
6,114,020
Members
448,543
Latest member
MartinLarkin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top