Incomplete Copy and Paste of Range

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,527
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I use this code to copy a range from one worksheet (filtered) to another.

Code:
        Worksheets("MasterWKSH").Range("A1:R300").Copy
        With Worksheets("CUE").Range("A1")
            .PasteSpecial xlPasteColumnWidths
            .PasteSpecial xlRowHeights
            .PasteSpecial xlPasteAll
        End With

The paste is not applying the row heights from the original worksheet. I thought .PasteSpecial xlRowHeights would cover that. And second, the original worksheet has a graphic that also needs to be copied over to the destination worksheet. How can I ensure that happens?
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

kevatarvind

Well-known Member
Joined
Mar 3, 2013
Messages
1,047
Office Version
  1. 365
Platform
  1. Windows
to paste rowheight use below code in your macro
Code:
Sub Test()
Sheets("CUE").Range("A1:A300").RowHeight = Sheets("MasterWKSH").Range("A1:A300").RowHeight
End Sub
 
Upvote 0

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,527
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi Kevatarvind ...

I tried that, and unfortunately ... it didn't do what was expected. No errors, but didn't apply the different row heights. :(

Jenn
 
Upvote 0

kevatarvind

Well-known Member
Joined
Mar 3, 2013
Messages
1,047
Office Version
  1. 365
Platform
  1. Windows
sorry pls try below one may be work to paste rowheight
Code:
Sub Test()
Sheets("CUE").Select
Range("A1").Select
i = 1
Do Until ActiveCell.Row = 300
ActiveCell.RowHeight = Sheets("MasterWKSH").Range("A" & i).RowHeight
ActiveCell.Offset(1, 0).Select
i = i + 1
Loop
End Sub
 
Upvote 0

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,527
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
ADVERTISEMENT
Hi ... that worked ... kinda.

The "MasterWKSH" worksheet is filtered. So, with the code you suggested ... it also hid rowson the destination sheet ... I'm assuming the row # hidden in the source worksheet (eg. row 12), was also hidden in the destination worksheet, even if that row was intended to be shown.

Does that make any sense?

Jenn
 
Upvote 0

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,527
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I think for what it's worth Kevatarvind, it might be easier to just assign each row the height rather than copy and paste. There aren't many rows.
The first 6 rows are different row heights. I know I can set the row height of each individual row in a seperate line of code, ie. rows(1).rowheight = 24, rows(2).rowheight=10 etc ...
This would require six lines of code. Is there a way to simply that? If I have a series of rows with the same height, I can use rows(12:22).rowheight=12.75

Jenn
 
Upvote 0

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
59,809
Office Version
  1. 365
Platform
  1. Windows
ADVERTISEMENT
The first 6 rows are different row heights. I know I can set the row height of each individual row in a seperate line of code, ie. rows(1).rowheight = 24, rows(2).rowheight=10 etc ...
This would require six lines of code. Is there a way to simply that? If I have a series of rows with the same height, I can use rows(12:22).rowheight=12.75
Jenn

For only 6 rows, the 6 lines of code is probably the simplest, but here's a couple of examples to consider if you have quite a few rows to deal with as they are more easily expandable.

1. Here's one for the first 6 rows.
Code:
Sub SetRowheights1()
  Dim r As Long
  Dim H
  
  Const RwH As String = "15 12.75 12.75 30 0 20" '<-Add more if you want
  
  H = Split(RwH)
  For r = 1 To UBound(H) + 1
    Rows(r).RowHeight = CDbl(H(r - 1))
  Next r
End Sub

2. Here's one if the rows are not necessarily sequential & may contain groups with the same height.
Code:
Sub SetRowHeights2()
  Dim i As Long
  Dim aRws, aHeights
  
  Const myRws As String = "1,2,3,4:20,30"     '<-Can add more
  Const myHeights As String = "25,35,0,8,54"  '<-Can add more
  
  aRws = Split(myRws, ",")
  aHeights = Split(myHeights, ",")
  For i = 0 To UBound(aRws)
    Rows(aRws(i)).RowHeight = CDbl(aHeights(i))
  Next i
End Sub
 
Upvote 0

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,527
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi Peter ... thanks for your reply and examples. I always appreciate an opportunity to learn.

I have never seen, let alone used, "Split". What is it's use, how does it work?

Cheers
 
Upvote 0

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
59,809
Office Version
  1. 365
Platform
  1. Windows
The Split function name is fairly descriptive. It splits a string into smaller parts based on some delimiter. In my first example I didn't specify a delimiter so a space is used by default. In my second example I used a comma as the delimiter. The Split function puts the "bits" created by the split into a zero-based array of strings.

So from my first code
Code:
  Dim H
  
  Const RwH As String = "15 12.75 12.75 30 0 20" '<-Add more if you want
  
  H = Split(RwH)
This produces
H(0) = "15"
H(1) = "12.75"
H(2) = "12.75"
H(3) = "30"
H(4) = "0"
H(5) = "20"

There is a corresponding Join function that does the opposite of Split. Look in the built-in vba Help for "Split Function" or "Join Function" for further information.
 
Upvote 0

kevatarvind

Well-known Member
Joined
Mar 3, 2013
Messages
1,047
Office Version
  1. 365
Platform
  1. Windows
Realy Mr Peter You Are Brilliant man you have lots of knowledge about excel and VB Daily i am learning from seeing your posts :) Keep doing Help
 
Upvote 0

Forum statistics

Threads
1,195,628
Messages
6,010,771
Members
441,568
Latest member
abbyabby

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
Top