Hello everyone
Hope someone can help me out on this. I'm trying to copy specific columns from one sheet and paste in another sheet in a different range.
I need to copy Column A, from the Source sheet and paste into Column A in Target sheet
and also copy Columns B:L and paste them into Columns H:R in Target sheet.
This is the code that I have, but maybe I am doing something wrong to achieve that ...Thank you in advance
Copying specific columns from one sheet and paste in another sheet in a different range
-
- StarLounger
- Posts: 68
- Joined: 03 Aug 2020, 05:23
Copying specific columns from one sheet and paste in another sheet in a different range
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78464
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Copying specific columns from one sheet and paste in another sheet in a different range
For example:
Code: Select all
Sub CopyColumns()
Dim r As Long
Dim c As Long
Sheet5.Columns("A").Copy Destination:=Sheet2.Range("A1")
Sheet5.Columns("B:L").Copy Destination:=Sheet2.Range("H1")
For r = 1 To Sheet5.UsedRange.Rows.Count
Sheet2.Rows(r).RowHeight = Sheet5.Rows(r).RowHeight
Next r
Sheet2.Cells(1, 1).ColumnWidth = Sheet5.Range("A1").ColumnWidth
For c = 2 To 12
Sheet2.Cells(1, c + 6).ColumnWidth = Sheet5.Cells(1, c).ColumnWidth
Next c
Application.CutCopyMode = False
Application.Goto Sheet2.Range("A8")
End Sub
Best wishes,
Hans
Hans
-
- BronzeLounger
- Posts: 1499
- Joined: 28 Feb 2015, 13:11
- Location: Hof, Bayern, Germany
Re: Copying specific columns from one sheet and paste in another sheet in a different range
I started before Hans posted, so I finished….
A similar attempt….
I don’t understand the logic to , or thinking behind, your macro Sub CopyColumns()
To answer this: …”….. I need to copy Column A, from the Source sheet and paste into Column A in Target sheet
and also copy Columns B:L and paste them into Columns H:R in Target sheet………”
and taking a bit of a guess at what you are not able to tell us..
Maybe something like this
A similar attempt….
I don’t understand the logic to , or thinking behind, your macro Sub CopyColumns()
To answer this: …”….. I need to copy Column A, from the Source sheet and paste into Column A in Target sheet
and also copy Columns B:L and paste them into Columns H:R in Target sheet………”
and taking a bit of a guess at what you are not able to tell us..
Maybe something like this
Code: Select all
Sub AfromSourceintoAinTargetandB_LintoH_RinTarget() ' https://eileenslounge.com/viewtopic.php?p=281753#p281753
Dim WsS As Worksheet, WsT As Worksheet
Set WsS = ThisWorkbook.Worksheets("Source"): Set WsT = ThisWorkbook.Worksheets("Target"):
Dim LrS As Long: Let LrS = WsS.Range("A" & WsS.Rows.Count & "").End(xlUp).Row
WsS.Range("A8:A" & LrS & "").Copy
WsT.Range("A8:A" & LrS & "").PasteSpecial
WsT.Range("A8:A" & LrS & "").PasteSpecial xlPasteColumnWidths
WsS.Range("B8:L" & LrS & "").Copy
WsT.Range("H8:R" & LrS & "").PasteSpecial
WsT.Range("H8:R" & LrS & "").PasteSpecial xlPasteColumnWidths
Dim Ar As Long
For Ar = 8 To LrS
WsT.Rows(Ar).RowHeight = WsS.Rows(Ar).RowHeight
Next Ar
End Sub
I am having difficulty logging in with this account just now.
You can find me at DocAElstein also
You can find me at DocAElstein also
-
- StarLounger
- Posts: 68
- Joined: 03 Aug 2020, 05:23
Re: Copying specific columns from one sheet and paste in another sheet in a different range
Thanks Hans and Doc.AElstein! Both macros works beautifully! Appreciate your help.