Copy Paste - Columns

sekar_r24

New Member
Joined
Apr 18, 2020
Messages
26
Office Version
  1. 2013
Platform
  1. Windows
Hi.,

i am trying to copy & paste the range of columns to two columns with specified criteria., Attached herewith the code so far.
the table consist of 6 columns. the first four columns are code nos with corresponding value in the last two column. i am trying to populate the following.
  1. first column to be placed in a certain location.
  2. the second column to be placed below the first column.
  3. the third column below the second column
  4. the fourth column below the third column.
  5. The value in the fifth column to be placed next column of the first column placed in sl.no:01
  6. the same value is placed again below the values pasted in the sl.no:5.
  7. The value in the sixth column to be placed below the sl.no:06
  8. the same value (sixth column) is placed again below the values pasted in the sl.no:7
the code i tried below, able to achieve upto sl.no:6
VBA Code:
Public Sub edgeband()
Dim x As Integer
Dim y As Integer ' column variable
Dim k As Integer ' column variable
Dim m As Integer ' column variable
Dim lngLastRow As Long
Dim lngLast As Long
m = 14
'to find the last row in the column.
'lry = Cells.Find("*", Cells(1, 1), xlFormulas, xlPart, xlByRows,xlPrevious, False).Row
lngLastRow = Cells(Rows.Count, "F").End(xlUp).Row
 Z = 13 ' destination column
 x = 3 'row no
y = 6 ' column no
k = 3
' toclear the last row
For y = 6 To 9
Range(Cells(x, y), Cells(lngLastRow, y)).Copy
Cells(k, Z).PasteSpecial xlPasteValues ' destination column
k = Cells(Rows.Count, Z).End(xlUp).Row + 1
Next y
Z = Z + 1
k = 3
For m = m To m + 2
Range(Cells(k, y), Cells(lngLastRow, y)).Copy
Cells(k, Z).PasteSpecial xlPasteValues
k = Cells(Rows.Count, Z).End(xlUp).Row + 1
Cells(k, Z).PasteSpecial xlPasteValues
y = y + 1
m = m + 1
x = 3
k = Cells(Rows.Count, Z).End(xlUp).Row + 1
Next m
Application.CutCopyMode = False
End Sub
How to achieve the 7th and 8th?
EB-L1EB-L2EB-W1EB-W2EB-LengthEB-Width
A1A2A3A4462550
A1A1A1A1562550
A2A2A2A2612550
A3A4A1A2912295


EBLength
A1462
A1562
A2612
A3912
A2462
A1562
A2612
A4912
A3550
A1550
A2550
A1295
A4550
A1550
A2550
A2295
A3550
A1550
A2550
A1295
A4550
A1550
A2550
A2295


Thanks
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
How about
VBA Code:
Public Sub edgeband()
Dim x As Integer, z As Long
Dim y As Integer ' column variable
Dim k As Integer ' column variable
Dim m As Integer ' column variable
Dim lngLastRow As Long
Dim lngLast As Long
m = 14
'to find the last row in the column.
'lry = Cells.Find("*", Cells(1, 1), xlFormulas, xlPart, xlByRows,xlPrevious, False).Row
lngLastRow = Cells(Rows.Count, "F").End(xlUp).Row
 z = 13 ' destination column
 x = 3 'row no
y = 6 ' column no
k = 3
' toclear the last row
For y = 6 To 9
   Range(Cells(x, y), Cells(lngLastRow, y)).Copy
   Cells(k, z).PasteSpecial xlPasteValues ' destination column
   k = Cells(Rows.Count, z).End(xlUp).Row + 1
Next y
z = z + 1
k = 3
For m = m To m + 1
   Range(Cells(x, y), Cells(lngLastRow, y)).Copy
   Cells(k, z).PasteSpecial xlPasteValues
   k = Cells(Rows.Count, z).End(xlUp).Row + 1
   Cells(k, z).PasteSpecial xlPasteValues
   y = y + 1
   k = Cells(Rows.Count, z).End(xlUp).Row + 1
Next m
Application.CutCopyMode = False
End Sub
 
Upvote 0
A slightly slimmed down version.
VBA Code:
Public Sub edgeband()
Dim x As Integer, z As Long
Dim y As Integer ' column variable
Dim k As Integer ' column variable
Dim m As Integer ' column variable
Dim lngLastRow As Long, Rws As Long

m = 10
'to find the last row in the column.
'lry = Cells.Find("*", Cells(1, 1), xlFormulas, xlPart, xlByRows,xlPrevious, False).Row
lngLastRow = Cells(Rows.Count, "F").End(xlUp).Row
 z = 13 ' destination column
 x = 3 'row no
 k = x
' toclear the last row
Rws = lngLastRow - x + 1
For y = 6 To 9
   Cells(k, z).Resize(Rws).Value = Cells(x, y).Resize(Rws).Value
   k = k + Rws
Next y
z = z + 1
k = x
For y = m To m + 1
   Cells(x, y).Resize(Rws).Copy
   Cells(k, z).Resize(Rws * 2).PasteSpecial xlPasteValues
   k = k + Rws * 2
Next y
Application.CutCopyMode = False
End Sub
 
Upvote 0
Thanks Fluff., works like a charm.
To get the sum of A1, A2, A3 & A4 separately, does autofilter -> Copy -> sum the values is the best way or any other wayaround?
 
Upvote 0
As that is a totally different question, you will need to start a new thread. Thanks
 
Upvote 0

Forum statistics

Threads
1,215,039
Messages
6,122,799
Members
449,095
Latest member
m_smith_solihull

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