Solved

Copy down cells, rewrite VBA

Posted on 2014-11-12
4
176 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

820 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