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:
No effect with that. Nothing happens on the values when I run the code.

I found that if I replace the periods (.) with slashes (/) with VBA, some of the values take a date form. For example, the text value of 1.9.2011 becomes the date of 9.1.2011. This is obviously a wrong date since the day and month are in wrong order (should be 1st of September) but at least the value is now in a date format.

Code:
Selection.Replace What:=".", Replacement:="/", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
Is it possible that the source report has some workbook-specific regional settings in it? Or can I utilize this somehow to get the correct dates?
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Did you try running the Text to columns manually?
What date separators does your machine normally use?
 
Upvote 0
I ran text to colums manually and it works when the separator is defined as ".".

Code:
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited _
        , TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
        :=".", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1)), _
        TrailingMinusNumbers:=True
The above (recorded) code inserts the day, month and year to three worksheet columns but what I'd like to have is to replace the initial text value in each cell with a date value.

How should I modify the code?
 
Upvote 0
You don't want to define the separator as anything in the string or you will get separate columns.
 
Upvote 0
This worked for me (Excel 2003):

Code:
Sub Macro2()
'
' Macro2 Macro
' Macro recorded 21/10/2011 by Andrew
'
'
    Columns("A:A").Select
    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
    Columns("A:A").EntireColumn.AutoFit
End Sub

Before and after:

1.9.2011 01/09/2011
31.12.2011 31/12/2011
 
Upvote 0

Forum statistics

Threads
1,216,095
Messages
6,128,795
Members
449,468
Latest member
AGreen17

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