Copy & Paste Values: Not working as I think it should (and another thing)

hip2b2

Board Regular
Joined
May 5, 2003
Messages
135
Office Version
  1. 2019
Platform
  1. Windows
Below is the code I am using (I know, not very sophisticate, but the best I know how to do).

Two Problems
1- I would like to copy the values (not the formulas) AND formatting from sheet "Prod Runs" to "Sheet 2". As it stands I get the values but lose the formatting.

2- "Sheet 2", "Row L" has several rows with the word "Closed" (these are random, e.g., they could be anywhere in the "Column L". I would like to know how to delete the rows where "Closed" is found in "Column L"


Any and all suggestions will be gratefully received.

Code:
Sub ACCT_MGR()

    Sheets("Sheet2").Select
    Cells.Select
    Application.CutCopyMode = False
    Selection.Delete Shift:=xlUp
    Range("A1").Select
    Sheets("Prod Runs").Select
    Columns("A:S").Select
    Selection.Copy
    Sheets("Sheet2").Select
    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False
    Columns("A:T").EntireColumn.AutoFit
    Columns("I:O").Select
    Application.CutCopyMode = False
    Selection.Delete Shift:=xlToLeft
    ActiveWindow.SmallScroll ToRight:=-1
    Columns("B:B").ColumnWidth = 25
    Columns("D:D").ColumnWidth = 1.5
    Columns("I:I").ColumnWidth = 2.5
    Range("A1").Select
    Sheets("Prod Runs").Select
    Range("A8").Select
End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
for your first question maybe try separate pasting values and number formats by replacing

Code:
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False

with

Code:
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
 
Upvote 0
for your first question maybe try separate pasting values and number formats by replacing

Code:
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False

with

Code:
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False

That worked perfectly except (I'm sure you hate the "excepts") that 2 rows have odd row heights (larger than required). I see nothing in those rows in the "copy from" sheet that would cause that.

Any fix you can suggest? Even if not thanks for your excellent fix.

hip
 
Upvote 0
not sure what could be causing it. maybe some text is getting wrapped or something
are your row heights all the same? you could maybe just add some row height code in after the paste special bit
Code:
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
    Selection.RowHeight = 15
 
Upvote 0
not sure what could be causing it. maybe some text is getting wrapped or something
are your row heights all the same? you could maybe just add some row height code in after the paste special bit
Code:
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
    Selection.RowHeight = 15

Thanks, that fixed it; though I still have no idea of what was the cause of the formatting "quirks" (not that it matters at this point).

hip
 
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,796
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