Solved

Copy down cells, rewrite VBA

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

786 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