N
Nancy
In an Excel spreadsheet of data I would like to do the following:
1. Insert 4 columns to the left of column N
2. Add titles to each of the four new columns
3. Add formulas to each of the four new columns in the third row
4. Copy the formulas down the rows thereby filling in the columns
with data
I have the following coding:
For Step 1:
Sub InsertColumns()
Columns("N:Q").Insert
End Sub
For Step 2-4:
Sub InsertFormulas()
Dim Lrow As Long
Dim CopyRange As Range
' Add Titles
Range("Q3").Select
ActiveCell.FormulaR1C1 = "Line Temp"
Range("P3").Select
ActiveCell.FormulaR1C1 = "Line"
Range("O3").Select
ActiveCell.FormulaR1C1 = "Length"
Range("N3").Select
ActiveCell.FormulaR1C1 = "Pos Val"
' Add Formulas
Range("Q6").Select
ActiveCell.FormulaR1C1 = "=MID(RC[1],2,2)"
Range("P6").Select
ActiveCell.FormulaR1C1 = "=TRIM(RC[1])"
Range("O6").Select
ActiveCell.FormulaR1C1 = "=LEN(RC[3])"
Range("N6").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-4]>0,RC[-4],0)"
Range("N6:Q6").Select
Lrow = Range("r65536").End(xlUp).Row
MsgBox Lrow
' Copy and Paste to end of target range
Selection.Copy
Range("N7:Q" & Lrow).Select
ActiveSheet.Paste
Range("A1").Select
End Sub
Each of these subroutines function properly if called separately.
However I would like to call only one subroutine, either by combining
the code into one or by having a subroutine call each of these two
subroutines such as:
Sub DoBoth()
InsertColumns
InsertFormulas
End Sub
However when I do either of those combining methods, it only runs the
"InsertColumns" part and then stops (no error messages). Could
someone please tell me what I am missing - why it will not continue on
and run the steps of the "InsertFormulas" subroutine?
Thanks,
Nancy
1. Insert 4 columns to the left of column N
2. Add titles to each of the four new columns
3. Add formulas to each of the four new columns in the third row
4. Copy the formulas down the rows thereby filling in the columns
with data
I have the following coding:
For Step 1:
Sub InsertColumns()
Columns("N:Q").Insert
End Sub
For Step 2-4:
Sub InsertFormulas()
Dim Lrow As Long
Dim CopyRange As Range
' Add Titles
Range("Q3").Select
ActiveCell.FormulaR1C1 = "Line Temp"
Range("P3").Select
ActiveCell.FormulaR1C1 = "Line"
Range("O3").Select
ActiveCell.FormulaR1C1 = "Length"
Range("N3").Select
ActiveCell.FormulaR1C1 = "Pos Val"
' Add Formulas
Range("Q6").Select
ActiveCell.FormulaR1C1 = "=MID(RC[1],2,2)"
Range("P6").Select
ActiveCell.FormulaR1C1 = "=TRIM(RC[1])"
Range("O6").Select
ActiveCell.FormulaR1C1 = "=LEN(RC[3])"
Range("N6").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-4]>0,RC[-4],0)"
Range("N6:Q6").Select
Lrow = Range("r65536").End(xlUp).Row
MsgBox Lrow
' Copy and Paste to end of target range
Selection.Copy
Range("N7:Q" & Lrow).Select
ActiveSheet.Paste
Range("A1").Select
End Sub
Each of these subroutines function properly if called separately.
However I would like to call only one subroutine, either by combining
the code into one or by having a subroutine call each of these two
subroutines such as:
Sub DoBoth()
InsertColumns
InsertFormulas
End Sub
However when I do either of those combining methods, it only runs the
"InsertColumns" part and then stops (no error messages). Could
someone please tell me what I am missing - why it will not continue on
and run the steps of the "InsertFormulas" subroutine?
Thanks,
Nancy