Better Way To Write This Code

Kurt

Well-known Member
Joined
Jul 23, 2002
Messages
1,664
I have this code:

Code:
Sub CopyPastefoo2()
'
' CopyPastefoo2 Macro
'

'
    Sheets("RawData").Select
    Range("A2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Sheets("DataCalcs").Select
    Range("AF2").Select
    Range("AF2").Formula = "=IF('RawData Old1'!A2=0,""Base Bid"", ""Alternate - "" & 'RawData Old1'!A2)"
    ActiveSheet.Paste
    Range("B2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Sheets("RawData").Select
    Selection.Copy
    Sheets("DataCalcs").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Sheets("RawData").Select
    Range("C2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets("DataCalcs").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Sheets("RawData").Select
    Range("D2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets("DataCalcs").Select
    Range("C2").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Sheets("RawData").Select
    Range("E2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets("DataCalcs").Select
    Range("D2").Select
    ActiveSheet.Paste
    Range("D2").Select
    Application.CutCopyMode = False
    Sheets("RawData").Select
    Range("F2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets("DataCalcs").Select
    Range("E2").Select
    ActiveSheet.Paste
    Range("E2").Select
    Application.CutCopyMode = False
    Sheets("RawData").Select
    Range("G2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets("DataCalcs").Select
    Range("F2").Select
    ActiveSheet.Paste
    Range("F2").Select
    Application.CutCopyMode = False
    Sheets("RawData").Select
    Range("H2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets("DataCalcs").Select
    Range("G2").Select
    ActiveSheet.Paste
    Sheets("DataCalcs").Select
    Range("G2").Select
    Application.CutCopyMode = False
    Sheets("RawData").Select
    Range("I2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets("DataCalcs").Select
    Range("H2").Select
    ActiveSheet.Paste
    Range("H2").Select
    Application.CutCopyMode = False
    Sheets("RawData").Select
    Range("J2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range("J2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range("K2").Select
    Sheets("DataCalcs").Select
    Range("J2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Application.CutCopyMode = False
    Range("J2").Select
    Sheets("RawData").Select
    Range("K2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets("DataCalcs").Select
    ActiveSheet.Paste
    Range("J2").Select
    Application.CutCopyMode = False
    Sheets("RawData").Select
    Range("L2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range("L2:L29089").Select
    Selection.Copy
    Sheets("DataCalcs").Select
    Range("K2").Select
    ActiveSheet.Paste
    Range("K2").Select
    Application.CutCopyMode = False
    Sheets("RawData").Select
    Range("M2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets("DataCalcs").Select
    Range("L2").Select
    ActiveSheet.Paste
    Range("L2").Select
    Application.CutCopyMode = False
    Sheets("RawData").Select
    Range("N2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets("DataCalcs").Select
    Range("M2").Select
    ActiveSheet.Paste
    Range("M2").Select
    Application.CutCopyMode = False
    Sheets("RawData").Select
    Range("O2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets("RawData").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("DataCalcs").Select
    Range("N2").Select
    ActiveSheet.Paste
    Sheets("RawData").Select
    Range("O2").Select
    Application.CutCopyMode = False
    Range("P2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets("DataCalcs").Select
    Range("O2").Select
    ActiveSheet.Paste
    Range("O2").Select
    Application.CutCopyMode = False
    Sheets("RawData").Select
    Range("Q2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets("DataCalcs").Select
    Range("P2").Select
    ActiveSheet.Paste
    Range("P2").Select
    Application.CutCopyMode = False
    Sheets("RawData").Select
    Range("R2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets("DataCalcs").Select
    Range("Q2").Select
    ActiveSheet.Paste
    Range("Q2").Select
    Application.CutCopyMode = False
    Sheets("RawData").Select
    Range("S2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range("S2:S29089").Select
    Selection.Copy
    Sheets("DataCalcs").Select
    Range("R2").Select
    ActiveSheet.Paste
    Range("R2").Select
    Application.CutCopyMode = False
End Sub

I know there should be a better way to write it.

The other problem is how do I copy that formula after copying and pasting the values from the RawData worksheet to enable the formula to see the new values?
 
Last edited by a moderator:

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Rather than trying to go through all the lines of code, could you explain what you want to do using words. It would be of great help if you could post a screen shot of what your data looks like? Section B at this link has instructions on how to post a screen shot: https://www.mrexcel.com/forum/board-announcements/127080-guidelines-forum-use.html Alternately, you could upload a copy of your file to a free site such as www.box.com. or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Include a detailed explanation of what you would like to do referring to specific cells, rows, columns and worksheets. If the workbook contains confidential information, you could replace it with generic data.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top