Solved

Copy down cells, rewrite VBA

Posted on 2014-11-12
4
174 Views
Last Modified: 2014-11-12
I finally got this to work, based on some examples,  How do I rewrite this to remove the sheet tab reference?  I know that these lines can be consolidated into a couple lines and do the same thing.  Please advise and thanks.

'Populate column B, copies value in B2 of sheet declared down B
'For as many rows that are in columnG, then copy/paste special values
    Range("B2").Select
    With Sheets("Kentwood Order Entry Sheet") 'the sheet tab name in SALESORDERDOWNLOAD.XML
        .Range("B3:B" & .Cells(.Rows.Count, "G").End(xlUp).Row).Formula = "=(B2)"
    End With
    Range(Selection, Selection.End(xlDown)).Select
    Application.CutCopyMode = False
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False

Open in new window

0
Comment
Question by:RWayneH
  • 2
4 Comments
 
LVL 24

Assisted Solution

by:Phillip Burton
Phillip Burton earned 200 total points
ID: 40437806
Assuming that the sheet that you want the code to work in is your current one, delete lines 4 and 6 and rewrite line 5 as follows:

Range("B3:B" & Cells(activesheet.Rows.Count, "G").End(xlUp).Row).Formula = "=(B2)"
0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40437809
You also don't need line 3.
0
 
LVL 27

Accepted Solution

by:
Glenn Ray earned 300 total points
ID: 40437824
Here's an edited version of your code.  I presumed you were on the "Kentwood" sheet the entire time:
'Populate column B, copies value in B2 of sheet declared down B
'For as many rows that are in columnG, then copy/paste special values
    Sheets("Kentwood Order Entry Sheet").Activate
    Range("B3:B" & Cells(Rows.Count, "G").End(xlUp).Row).Formula = "=B2"

    Range("B2", Range("B2").End(xlDown)).Copy
    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats

Open in new window


Regards,
-Glenn
0
 

Author Closing Comment

by:RWayneH
ID: 40437889
Thanks for the help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

919 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now