Solved

Excel VB for copying formulas from last row to the next row

Posted on 2011-02-13
8
505 Views
Last Modified: 2012-05-11
Hi all!  Another stupid newbie question.

I am attempting to copy the formulas from the last line to the next open line after that line in Excel 2007.  Below is the code but it keeps copying the formula a the starting cell B11 instead of the next open line.  I know the problem is the line of code

 Range("B11").Select

How do I change that code to copy from the last line to the next open line ("B11") was the line that was open when I recorded my macro.

Sub CopyNewPayDatesAddtlInfo()
'
' Macro14 Macro
'

'
    Range("B4").Select
    Selection.End(xlDown).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Selection.Copy
    Range("B11").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Range("B4").Select
End Sub

Open in new window

0
Comment
Question by:wlwebb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
8 Comments
 
LVL 20

Expert Comment

by:Ardhendu Sarangi
ID: 34883100
Hi wlwebb,
I think there is a lot of redundant lines in this code. can you please explain what you are trying to do here?

- Ardhendu
0
 
LVL 20

Assisted Solution

by:Ardhendu Sarangi
Ardhendu Sarangi earned 500 total points
ID: 34883120
Here's one way to achieve what you are trying to do
Sub CopyNewPayDatesAddtlInfo()
' Macro14 Macro
    n = Cells(65536, "B").End(xlUp).Row
    Range("B" & n + 1).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Selection.FillDown
End Sub

Open in new window

0
 

Author Comment

by:wlwebb
ID: 34883152
Pari
I know that there are easier ways to do what I am attempting.  Just not very good at it yet so you can only go with what you know.  

Anyway, in looking at your code I have a question.  In the line  (n = Cells(65536, "B").End(xlUp).Row) why put that line of code in?  What is the purpose of 65536?  What happens when the user reaches line 65537 of data?

Keep in mind, I am only wanting to copy the formula to one row, that row being the very next open line and to that line only.  Will you code accomplish that?  Or will it copy that formula all the way down to line 65536?
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 20

Accepted Solution

by:
Ardhendu Sarangi earned 500 total points
ID: 34883169

1. the 65536 is the last row that exists in excel 2003.
2. so the code in line 3 is checking to find what is the last row that was used in Column B. basically, the code starts checking the cells backwards from 65536 till it reaches a cell that is not empty.
3. next the macro will copy the last line of data and paste it ONLY in the next row.

try the macro once and see if that works for you,

- Ardhendu
0
 

Author Closing Comment

by:wlwebb
ID: 34883266
Thanks for the input
0
 
LVL 20

Expert Comment

by:Ardhendu Sarangi
ID: 34883275
Hi wlwebb,

is there a reason for grading this as B? Please see the following help section on the grades to give.

http://www.experts-exchange.com/help.jsp#hs=29&hi=403 

thanks,
Ardhendu

0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34897030
Instead of 65536, you should get in the habit of using Rows.Count so it will be compatible across all versions.
Also, a B grade is supposed to be used if the experts didn't really get you the solution.
Since you didn't ask any further questions pari certainly assumed that you didn't need any more help. It does not appear to me that anything was lacking.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question