• 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.

VB code to change a column of text numbers to Numbers

seansr

Member
I have a macro in a spreadsheet that deletes all on one sheet, then opens another spreadsheet, copies it and then goes back to the first sheetwhere it should then do some Vlookups and create an order based on an orer being geneterated by another system but in totally the wrong format

The code I have is:
Code:
Sheets("Symphony Order").Select
  Cells.Select
  Selection.Clear
  Workbooks.Open Filename:="C:\Symphony Exports\Report_Order.xls"
  Cells.Select
  Selection.Copy
  Windows("Anchor 4th Nov .xls").Activate
  Sheets("Symphony Order").Select
  Selection.PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
  Application.DisplayAlerts = False
  Windows("Report_Order.xls").Activate
  ActiveWindow.Close
  Windows("Anchor 4th Nov .xls").Activate
  Sheets("TUCOStMarys").Activate
  Range("D1").Select
I want all the numbers in Column Hin the Anchor 4th Nov .xls sheet which are copied as Text to be converted to Numbers, otherwise my lookups are not working in the TUCOStMarys sheet
 
Last edited by a moderator:
What about just changing the line
From:
Selection.PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

To:
Selection.PasteSpecial Paste:=xlPasteAsValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
 
As @Hui suggested you are free to try the same meanwhile you might interested to share the workbook so that we can diagnosis it. TEXT type data could converted to numeric based on requirement either in xl formula itself or by VBA.

I have alter your current code...
Code:
With Sheets("Symphony Order")
    .UsedRange.Cells.Clear
        Workbooks.Open Filename:="C:\Symphony Exports\Report_Order.xls"
            ActiveSheet.UsedRange.Copy
            .PasteSpecial Paste:=xlPasteAsValues
'            .Paste
        ActiveSheet.Parent.Close False
End With
    Sheets("TUCOStMarys").Activate
    Range("D1").Select
 
I have tried both of your suggestions but on both I get a Compile Error: Viarable not Defined on the xlPasteAsValues part
 
Back
Top