copy data from range to range in the same sheet same width & height columns and rows

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,429
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
hi
i need copy data from A1:D TO F1 :I with the same width and height column and row in the same sheet this is my code but it doesn't work well
VBA Code:
Sub rr()
Sheets("sheet1").Range("A1:d1000").Copy Destination:=Sheets("sheet1").Range("f1")
Selection.PasteSpecial Paste:=xlPasteColumnWidths
Selection.PasteSpecial Paste:=xlPasteRowHeights
Selection.PasteSpecial Paste:=xlPasteValuesandFormats, Operation:=xlNone, SkipBlanks _
 :=False, Transpose:=False

End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
You wouldnt use selection for the paste special. You would use the
VBA Code:
Sheets("sheet1").Range("f1")
as you did for the paste
 
Upvote 0
i no know if you mean this
VBA Code:
Sub rr()
Sheets("sheet1").Range("A1:d100").Copy Destination:=Sheets("sheet1").Range("f15")
Sheets("sheet1").Range("f15").PasteSpecial Paste:=xlPasteColumnWidths
Sheets("sheet1").Range("f15").PasteSpecial Paste:=xlPasteRowHeights
Sheets("sheet1").Range("f15").PasteSpecial Paste:=xlPasteValuesandFormats, Operation:=xlNone, SkipBlanks _
 :=False, Transpose:=False

End Sub


but still problem
 
Upvote 0
what about width i issue this code to somebody adjusting i'm beginner in vba
 
Upvote 0
Ok you can do fiddly things with row heights but your paste area is in the same rows as the copy area which isnt going to work. However try this:

VBA Code:
Dim copyrng As Range, pasterng As Range, arr, i As Long, fr As Long

With Sheets("Sheet1")
    'set ranges for copy and paste
    Set copyrng = .Range("A1:D100")
    Set pasterng = .Range("F15")
    'get row heights copy range
    ReDim arr(1 To copyrng.Rows.Count)
    For i = LBound(arr) To UBound(arr)
        arr(i) = copyrng.Cells(i, 1).RowHeight
    Next
    'change row height paste range
    fr = pasterng.Cells(1).Row
    For i = fr To UBound(arr) + fr - 1
        .Rows(i).RowHeight = arr(i - fr + 1)
    Next
    'use paste special for the rest
    copyrng.Copy
    pasterng.PasteSpecial Paste:=xlPasteColumnWidths
    pasterng.PasteSpecial Paste:=xlPasteAll
End With
 
Upvote 0

Forum statistics

Threads
1,214,935
Messages
6,122,337
Members
449,078
Latest member
skydd

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