Consulting

Results 1 to 7 of 7

Thread: Solved: Change text to numbers for different sheets and workbooks

  1. #1

    Cool Solved: Change text to numbers for different sheets and workbooks

    Hi Experts,

    I want my code below does the same in 45 sheets and 11 workbooks. (change text to numbers in a variable range)



    [VBA]Dim rrGlobal As Range
    Sub ChangeUPCtonumbers()
    Set rrGlobal = Range("A:A")
    Call ChangeUPCtonumbers1
    End Sub


    Sub ChangeUPCtonumbers1()

    Dim r As Range

    Count = 0
    For Each r In rrGlobal
    If Application.IsText(r.Value) Then
    If IsNumeric(r.Value) Then
    r.Value = 1# * r.Value
    r.NumberFormat = "General"
    Count = Count + 1
    End If
    End If
    Next
    MsgBox (Count & " cells changed")
    End Sub[/VBA]

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Dim rrGlobal As Range
    Dim sh As Worksheet
    For Each sh In ActiveWorkbook.Worksheets
    Sub ChangeUPCtonumbers()
    Set rrGlobal = sh.Range("A:A")
    Call ChangeUPCtonumbers1
    Next sh
    End Sub


    Sub ChangeUPCtonumbers1()
    Dim r As Range

    Count = 0
    For Each r In rrGlobal
    If Application.IsText(r.Value) Then
    If IsNumeric(r.Value) Then
    r.Value = 1# * r.Value
    r.NumberFormat = "General"
    Count = Count + 1
    End If
    End If
    Next
    MsgBox (Count & " cells changed")
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3

    Change text to numbers for different sheets and workbooks

    Hi xld,

    Thank you very much for your answer.

    It is working perfect in all the sheets for 1 woorkbook, but it is not doing anything in the other opened woorkbooks.

    Thanks

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]
    Dim rrGlobal As Range
    Dim sh As Worksheet
    For each wb In Workbooks
    For Each sh In wb.Worksheets
    Sub ChangeUPCtonumbers()
    Set rrGlobal = sh.Range("A:A")
    Call ChangeUPCtonumbers1
    Next sh
    Next wb
    End Sub
    [/vba]


    __________________________________________
    UK Cambridge XL Users Conference 29-30 Nov
    http://www.exceluserconference.com/UKEUC.html
    Last edited by Bob Phillips; 11-22-2007 at 11:25 AM.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    Hi xld,

    Thanks, now it is working perfect!!

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Please mark the thread as solved then.


    __________________________________________
    UK Cambridge XL Users Conference 29-30 Nov
    http://www.exceluserconference.com/UKEUC.html
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    You do realize that if you loop through all open workbooks you'll loop through all hidden instances of workbooks as well, i.e. Personal.xls.

    HTH

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •