ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Shouldn't this work? (https://www.excelbanter.com/excel-programming/352314-shouldnt-work.html)

Jonathan Cooper

Shouldn't this work?
 
Sub KillIt()
'
' After you have copied a range(i.e., pivot table), this macro
' is used to paste it in inert form, for distribution
' to non-technical users.

If Application.CutCopyMode = True Then
With Selection
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
.PasteSpecial Paste:=xlPasteColumnWidths
End With
Else: MsgBox ("You have to copy, before you can paste")
End If
End Sub

When I run this, even after copying a range, it still defaults to the ELSE
section.

The purpose of the macro, is to PASTE, and I want to make sure the user has
copied something, before they run the macro.

PCLIVE

Shouldn't this work?
 
I don't think "Else" should be followed by a colon ":".

Paul

"Jonathan Cooper" wrote in
message ...
Sub KillIt()
'
' After you have copied a range(i.e., pivot table), this macro
' is used to paste it in inert form, for distribution
' to non-technical users.

If Application.CutCopyMode = True Then
With Selection
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
.PasteSpecial Paste:=xlPasteColumnWidths
End With
Else: MsgBox ("You have to copy, before you can paste")
End If
End Sub

When I run this, even after copying a range, it still defaults to the ELSE
section.

The purpose of the macro, is to PASTE, and I want to make sure the user
has
copied something, before they run the macro.




Charlie

Shouldn't this work?
 
Actually the colon is an old and little-used syntax for putting multiple
statements on one line, e.g.

For i = 1 To 3: Debug.Print i: Next i

Try this to fix your problem:

If Application.CutCopyMode Then
With Selection
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
.PasteSpecial Paste:=xlPasteColumnWidths
End With
Else
MsgBox ("You have to copy, before you can paste")
End If

"PCLIVE" wrote:

I don't think "Else" should be followed by a colon ":".

Paul

"Jonathan Cooper" wrote in
message ...
Sub KillIt()
'
' After you have copied a range(i.e., pivot table), this macro
' is used to paste it in inert form, for distribution
' to non-technical users.

If Application.CutCopyMode = True Then
With Selection
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
.PasteSpecial Paste:=xlPasteColumnWidths
End With
Else: MsgBox ("You have to copy, before you can paste")
End If
End Sub

When I run this, even after copying a range, it still defaults to the ELSE
section.

The purpose of the macro, is to PASTE, and I want to make sure the user
has
copied something, before they run the macro.





impslayer

Shouldn't this work?
 
"Jonathan Cooper" wrote in
message ...
Sub KillIt()
'
' After you have copied a range(i.e., pivot table), this macro
' is used to paste it in inert form, for distribution
' to non-technical users.

If Application.CutCopyMode = True Then
With Selection
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
.PasteSpecial Paste:=xlPasteColumnWidths
End With
Else: MsgBox ("You have to copy, before you can paste")
End If
End Sub

When I run this, even after copying a range, it still defaults to the ELSE
section.

The purpose of the macro, is to PASTE, and I want to make sure the user
has
copied something, before they run the macro.


Don't think CutCopyMode really returns True like that, rather xlCopy,
xlCut or False, so your code should be changed to check for False
instead, and moving the paste code to the else branch.

/impslayer, aka Birger Johansson


Jonathan Cooper

Shouldn't this work?
 
That appears to have done the trick. Thanks.

"Charlie" wrote:

Actually the colon is an old and little-used syntax for putting multiple
statements on one line, e.g.

For i = 1 To 3: Debug.Print i: Next i

Try this to fix your problem:

If Application.CutCopyMode Then
With Selection
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
.PasteSpecial Paste:=xlPasteColumnWidths
End With
Else
MsgBox ("You have to copy, before you can paste")
End If

"PCLIVE" wrote:

I don't think "Else" should be followed by a colon ":".

Paul

"Jonathan Cooper" wrote in
message ...
Sub KillIt()
'
' After you have copied a range(i.e., pivot table), this macro
' is used to paste it in inert form, for distribution
' to non-technical users.

If Application.CutCopyMode = True Then
With Selection
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
.PasteSpecial Paste:=xlPasteColumnWidths
End With
Else: MsgBox ("You have to copy, before you can paste")
End If
End Sub

When I run this, even after copying a range, it still defaults to the ELSE
section.

The purpose of the macro, is to PASTE, and I want to make sure the user
has
copied something, before they run the macro.





Jonathan Cooper

Shouldn't this work?
 
VBA put that in there automatically. I deleted it, and VBA put it back in
there again.

"PCLIVE" wrote:

I don't think "Else" should be followed by a colon ":".

Paul

"Jonathan Cooper" wrote in
message ...
Sub KillIt()
'
' After you have copied a range(i.e., pivot table), this macro
' is used to paste it in inert form, for distribution
' to non-technical users.

If Application.CutCopyMode = True Then
With Selection
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
.PasteSpecial Paste:=xlPasteColumnWidths
End With
Else: MsgBox ("You have to copy, before you can paste")
End If
End Sub

When I run this, even after copying a range, it still defaults to the ELSE
section.

The purpose of the macro, is to PASTE, and I want to make sure the user
has
copied something, before they run the macro.





Tushar Mehta

Shouldn't this work?
 
Check XL VBA's help for CutCopyMode. Pay particular attention to the table
that lists the returned values.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
Sub KillIt()
'
' After you have copied a range(i.e., pivot table), this macro
' is used to paste it in inert form, for distribution
' to non-technical users.

If Application.CutCopyMode = True Then
With Selection
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
.PasteSpecial Paste:=xlPasteColumnWidths
End With
Else: MsgBox ("You have to copy, before you can paste")
End If
End Sub

When I run this, even after copying a range, it still defaults to the ELSE
section.

The purpose of the macro, is to PASTE, and I want to make sure the user has
copied something, before they run the macro.


Jonathan Cooper

Shouldn't this work?
 
Thank you.






"Tushar Mehta" wrote:

Check XL VBA's help for CutCopyMode. Pay particular attention to the table
that lists the returned values.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
Sub KillIt()
'
' After you have copied a range(i.e., pivot table), this macro
' is used to paste it in inert form, for distribution
' to non-technical users.

If Application.CutCopyMode = True Then
With Selection
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
.PasteSpecial Paste:=xlPasteColumnWidths
End With
Else: MsgBox ("You have to copy, before you can paste")
End If
End Sub

When I run this, even after copying a range, it still defaults to the ELSE
section.

The purpose of the macro, is to PASTE, and I want to make sure the user has
copied something, before they run the macro.




All times are GMT +1. The time now is 10:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com