• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Pastespecial VBA code error

Hi All,

in my sheet2 range(P6:Z23) dashboard, when i select april radio button the dashboard should paste in same fomate in ("b6) iam not getting proper output while iam running this code please help on same. excel file enclosed for reference..

Code:
Sub OptionButton1_Click()
  Rows("6:23").Select
  Selection.Delete Shift:=xlUp
  Columns("a:l").Select
  Selection.Delete Shift:=xlToLeft
  Sheet2.Range("b6").PasteSpecial Paste:=xlPasteAll, Operation:=xlPasteSpecialOperationNone, SkipBlanks:=False _
  , Transpose:=False = Sheet2.Range("P6:Z23").Copy
  Application.CutCopyMode = False
  Columns("b:L").EntireColumn.AutoFit
  Columns("B:L").EntireColumn.AutoFit
  Columns("B:L").EntireColumn.AutoFit
 
End Sub
 

Attachments

Last edited by a moderator:
Code:
Sub OptionButton1_Click()
  Rows("6:23").Select
  Selection.Delete Shift:=xlUp
  Columns("a:l").Select
  Selection.Delete Shift:=xlToLeft
  Sheet2.Range("P6:Z23").Copy
  Sheet2.Range("b6").PasteSpecial Paste:=xlPasteAll, Operation:=xlPasteSpecialOperationNone, SkipBlanks:=False _
  , Transpose:=False
  Application.CutCopyMode = False
  Columns("b:L").EntireColumn.AutoFit
  Columns("B:L").EntireColumn.AutoFit
  Columns("B:L").EntireColumn.AutoFit

EndSub
 
Hi ,

Your first 2 lines of code are :
Code:
  Rows("6:23").Select
  Selection.Delete Shift:=xlUp
Once you have deleted all the rows from 6 to 23 , what will the range P6:Z23 contain ?

Narayan
 
Your code cleaned up should be
Code:
  Sheet2.Rows("6:23").Delete Shift:=xlUp
  Sheet2.Columns("A:L").Delete Shift:=xlToLeft
 
  Sheet2.Range("P6:Z23").Copy
  Sheet2.Range("b6").PasteSpecial _
    Paste:=xlPasteAll, _
    Operation:=xlPasteSpecialOperationNone, _
    SkipBlanks:=False, _
    Transpose:=False
  Application.CutCopyMode = False
  Columns("B:L").EntireColumn.AutoFit
 
Back
Top