ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Paste a value (SUM) (https://www.excelbanter.com/excel-programming/337762-paste-value-sum.html)

[email protected]

Paste a value (SUM)
 
Hi!

In the clipboard I have a number (e.g. 123,40) which I want insert via
a VBA-Macro into a special cell. In an other cell there is a
SUM-Function which includes also the one where the value was
automatically pasted in.

Now there is the problem that after pasting the value it doesn't appear
in the sum unless I made a double click on the cell.

Does anybody have a hint?

Best Regards,
Nachtigall


Charlie

Paste a value (SUM)
 
In your code somewhere have you turned off automatic calculation? If so you
will need to turn it back on at the end of your sub. I tried doing this and
it worked fine. The calculation was: "B2=SUM(A1:A2)" Cell B2 was not
updated until after automatic calculation was turned on.

Application.Calculation = xlCalculationManual
Range("A1") = ClipboardGetText
Application.Calculation = xlCalculationAutomatic


Public Function ClipboardGetText() As String

' (works the same as VB6 Clipboard.GetText function)

Dim objDataObject As New DataObject

objDataObject.GetFromClipboard
ClipboardGetText = objDataObject.GetText(1)

End Function


" wrote:

Hi!

In the clipboard I have a number (e.g. 123,40) which I want insert via
a VBA-Macro into a special cell. In an other cell there is a
SUM-Function which includes also the one where the value was
automatically pasted in.

Now there is the problem that after pasting the value it doesn't appear
in the sum unless I made a double click on the cell.

Does anybody have a hint?

Best Regards,
Nachtigall



[email protected]

Paste a value (SUM)
 
Do you really use VBA (or VisualBasic)?

Because I do not use the "GetFromClipboard"-Expression but
"ActiveSheet.Paste". Maybe this could be the error?


Charlie

Paste a value (SUM)
 
I guess I misunderstood how you were pasting. I tried both methods and
discovered they don't exactly work the same. For example, if I copy lines
from this post by highlighting and using Ctrl-C, the ActiveSheet.Paste will
paste more than just text. It pastes formats, fonts, multiple lines into
multiple cells, etc. My method simply pastes text only into one cell, with
multiple lines as one text string having embedded CRLF's.

But, if I copy and paste a single number into one cell using either method
the calculation shows up immediately. I'm not sure what to tell you. I'm
still kind of new to Excel and VBA programming.

Did you check to see if automatic calculation is turned off somewhere?

I need to hit the road. Sorry I couldn't be of more assistance. Have a
nice weekend.

" wrote:

Do you really use VBA (or VisualBasic)?

Because I do not use the "GetFromClipboard"-Expression but
"ActiveSheet.Paste". Maybe this could be the error?




All times are GMT +1. The time now is 02:50 AM.

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