PasteSpecial multiply doesn't work with Excel 2010

Nuz

Board Regular
Joined
Aug 16, 2010
Messages
88
In Excel 2002 I used the VBA code that selected a range and multiplied that range by a value of 1.
When changed to Excel 2010, this code does not work anymore.
The code is:
Code:
Range("A1").FormulaR1C1 = "1"
Range("A1").Copy
Range(Cells(2, 1), Cells(100, 1)).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlMultiply, SkipBlanks:=True, Transpose:=False
If I do it manually, it works in Excel 2010 but the above VBA code cannot do it.

I also used this:
Code:
Selection.Value = Selection.Value
But it doesn't work either.

The worksheet where I try to apply this is a database report where certain numbers are in text format and therefore I need to convert them to numbers before using the in my models.
I also noticed that the probelm occurs when the initial value has either a comma (,) or point (.) in it. For example, a text 21,1 cannot be converted but the text 21 can.
Also dates, like 31.12.2012 have the same problem.

Can this be fixed somehow?
 
Last edited:

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
I tried that. It didn't work.

When I replace the commas with points through VBA like that:
Code:
Selection.Replace What:=",", Replacement:=".", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
...the text values instantly become numerical.

However, if I do the same replacing manually, the values become dates.
For example, the initial text value of 14,5 becomes 14.5.2011 if done manually but becomes correctly a decimal value if done through VBA (with the code above).

I really don't understand why this behaves so since I recorded the above macro. So it should do exactly the same thing that doing it manually.
 
Upvote 0
I really don't understand why this behaves so since I recorded the above macro. So it should do exactly the same thing that doing it manually.

It should but that is not always the case, since VBA assumes US regional settings by default. Since the period is not a date separator in the US, it does not convert to dates when you run the code.
 
Upvote 0
I see.

Within dates, in every cell I now need to manually go to formula bar and press enter. After doing so, the dates are displayed correctly as dates (and aligned to right). I kind of have to re-enter the value to a cell.
I still think this is due to the report that is extracted from the database.

Can I similarly "re-enter" the values vith VBA somehow? I have over 10,000 rows to go through.
 
Upvote 0
You can usually just select all the data, use Data-Text to columns, Delimited and in step 3 specify the date order. That will do all of them at once.
 
Upvote 0
For example:
Code:
    Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
        :=Array(1, 4), TrailingMinusNumbers:=True

this assumes DMY date order.
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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