Copy selected column data and paste into another sheet.

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,422
Office Version
  1. 2010
Using Excel 2010

Hello,

In the “sheet data” from column “C to Column P” I have header “n1 to n14” Out of 14 columns I want to select any 10 columns and copy them into the sheet “Copy 10 Columns” in the range C5:L5 below including one row header…

For example in the “sheet data” if I select by mouse cell C5, D5, F5, H5, J5, K5, L5, N5, O5, P5 (10 COLUMNS) Is it possible all column data till row 40 can be copied and paste in to sheet “Copy 10 Columns” in the range C5:L5 below including one row header…

Please see the example data… request need VBA solution.

Trails.xlsm
ABCDEFGHIJKLMNOPQR
1YEARSeriol Numn1n2n3n4n5n6n7n8n9n10n11n12n13n14EM1Sum
2YEARSeriol Numn1n2n3n4n5n6n7n8n9n10n11n12n13n14EM1Sum
3YEARSeriol Numn1n2n3n4n5n6n7n8n9n10n11n12n13n14EM1Sum
4YEARSeriol Numn1n2n3n4n5n6n7n8n9n10n11n12n13n14EM1Sum
5YEARSeriol Numn1n2n3n4n5n6n7n8n9n10n11n12n13n14EM1Sum
6200611601997828427278517118181991771501350
72006243186128971452974152130188581851701051690
820063182295517812713750132164849949731179
920064271351701003911549491115442131161601243
1020065231651612559601671724714616012177951469
112006615219864141421601904818610915337171380
12200671711168815615620060105136185773197871737
1320068158363954557423889213912411931681244
14200691078931161771041211231689819486197761668
1520071013978183601117819064811478477251571474
16200711759491161251491061021407451041541145
172007129195100562311617410838104149478951231
18200713131091053166121395215471192164106391253
19200714105188811441748011951745018868163231544
2020071524017421926119243196147107439781196
2120071639661833959126124522264508289191014
222007177590112116181196351229166148251671531595
23200718146166131160137193170195124196010041791721
242007194557812251581241477314719212993671313
252007201462026144015816710119315519329182971521
26200721129286561231641641597227496240881221
272007223669143124177102252017918333170551361452
28200723179801191501218213462149994791241601542
29200824181331291001788169235011317971781841370
302008252077375316910269185591701061271531831510
312008269619410214610410511319016437155763571524
322008278510879517161697145668067481671104
33200828146106241263254186755682105101292001331
34200829275412512411030785413335187147125261255
3520083011918435221961819450621451976161071306
362008315619578121161455655318512868851451381
372008321551051805319712011413297200135144157811870
38200833126141778013313384753215773107107821380
39200834147584164516214914234103102179331961478
4020093514716479120691593779126349590481211
41200936
42200937
43200938
44200939
45200940
46200941
47201042
Data


Expected Result...10 columns
Trails.xlsm
ABCDEFGHIJKLMN
1
2
3
4
5YEARSeriol Numn1n2n4n6n8n9n10n12n13n14EM1Sum
620061160199287285171181991771501205
7200624318697291521301881851701051285
82006318225112750132164994973785
92006427135100115491115413116160943
1020065231652560172471461217795922
1120066152198141211904818615337171143
122006717111615620010513618573197871426
1320068158365474889213911931681003
142006910781161041231689886197761083
152007101397860178648114777251571006
162007117594161491021405104154749
172007129195561161083810447895785
18200713131093112521547116410639751
1920071410518814480951745068163231090
2020071524021614319614743978631
21200716396639126522264828919598
2220071775901161961229166251671531119
232007181461661601931951241910041791223
24200719455712258147731471299367938
25200720146201415810119315529182971095
262007211292561641597227624088799
27200722366912410220179183170551361074
282007231798015082621499791241601074
292008241813310081235011397178184977
30200825207753102185591701271531831129
312008269619414610519016437763571050
322008278510851617145666748167859
332008281461061265475568210129200984
34200829275412430541333514712526755
352008301191842218150621457616107962
3620083156195121455531856885145958
372008321551055312013297200144157811244
382008331261480133753215710710782913
392008341475816416214234103179331961218
4020093514716412015979126349048931
41200936
42200937
43200938
44200939
45200940
Copy 10 Columns


Regards,
Moti
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
A quick one as I am on the way to do other things.
Adapt as required by changing references. If it does not do what you need after adjusting, come back and let us know.
Code:
Sub Maybe_So()
Dim c As Range, rng As Range
    For Each c In Selection
        If rng Is Nothing Then
            Set rng = c.Resize(35)    '<---- ?????
                Else
            Set rng = Union(rng, c.Resize(35))    '<---- ?????
        End If
    Next c
rng.Copy Sheets("Sheet2").Cells(5, 3)    '<---- Change sheet name and cell address
End Sub
 
Upvote 0
A quick one as I am on the way to do other things.
Adapt as required by changing references. If it does not do what you need after adjusting, come back and let us know.
Code:
Sub Maybe_So()
Dim c As Range, rng As Range
    For Each c In Selection
        If rng Is Nothing Then
            Set rng = c.Resize(35)    '<---- ?????
                Else
            Set rng = Union(rng, c.Resize(35))    '<---- ?????
        End If
    Next c
rng.Copy Sheets("Sheet2").Cells(5, 3)    '<---- Change sheet name and cell address
End Sub
Hello jolivanes, yes code worked perfect as requested. I could modified the “IngLastRow” range from column “C” here below the code is attached.

Please I need further help instead of paste all. Is it possible to paste only the values?

I appreciate your support.

VBA Code:
Sub Maybe_So()

    Dim lngLastRow As Long
    lngLastRow = Cells(Rows.Count, "C").End(xlUp).Row - 4
 
    Dim c As Range, rng As Range
    For Each c In Selection
        If rng Is Nothing Then
            Set rng = c.Resize(lngLastRow)    '<---- ?????
                Else
            Set rng = Union(rng, c.Resize(lngLastRow))    '<---- ?????
        End If
    Next c
 
    rng.copy Sheets("Sheet2").Cells(5, 3)   '<---- Change sheet name and cell address
 
 
End Sub

Kind Regards,
Moti :)
 
Last edited:
Upvote 0
Hello jolivanes, Please I need further help instead of paste all. Is it possible to paste only the values?

Kind Regards,
Moti :)

Hello Jolivanes, finally also I could manage to paste values only. Please can you check the code if there is any error make it correct. Thank you.
Have a nice day good luck.

VBA Code:
Sub Maybe_So()

    Sheets("Sheet2").Range("C5:M5006").ClearContents
  
    Dim lngLastRow As Long
    lngLastRow = Cells(Rows.Count, "C").End(xlUp).Row - 4
  
    Dim c As Range, rng As Range
    For Each c In Selection
        If rng Is Nothing Then
            Set rng = c.Resize(lngLastRow)    'Set Last Range
                Else
            Set rng = Union(rng, c.Resize(lngLastRow))    'Set Union Last Range
        End If
    Next c
  
    rng.copy
    Sheets("Sheet2").Range("C5").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    Range("C6").Select
  
End Sub
Kind Regards,
Moti
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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