Consulting

Results 1 to 4 of 4

Thread: How to set loop for selecting columns and converting numbers stored as text

  1. #1

    How to set loop for selecting columns and converting numbers stored as text

    hi,
    how to set this in a loop, please help
    Range("C1:C" & FinalRow).Select
                Range(Selection, Selection.End(xlDown)).Select
                With Selection
                Selection.NumberFormat = "General"
                .Value = .Value
                End With
                
                Range("D1:D" & FinalRow).Select
                Range(Selection, Selection.End(xlDown)).Select
                With Selection
                Selection.NumberFormat = "General"
                .Value = .Value
                End With
                
                Range("F1:F" & FinalRow).Select
                Range(Selection, Selection.End(xlDown)).Select
                With Selection
                Selection.NumberFormat = "General"
                .Value = .Value
                End With
                
                Range("L1:L" & FinalRow).Select
                Range(Selection, Selection.End(xlDown)).Select
                With Selection
                Selection.NumberFormat = "General"
                .Value = .Value
                End With
                
                Range("P1:P" & FinalRow).Select
                Range(Selection, Selection.End(xlDown)).Select
                With Selection
                Selection.NumberFormat = "General"
                .Value = .Value
                End With
                
                Range("T1:T" & FinalRow).Select
                Range(Selection, Selection.End(xlDown)).Select
                With Selection
                Selection.NumberFormat = "General"
                .Value = .Value
                End With
                
                Range("V1:V" & FinalRow).Select
                Range(Selection, Selection.End(xlDown)).Select
                With Selection
                Selection.NumberFormat = "General"
                .Value = .Value
                End With
                
                Range("W1:W" & FinalRow).Select
                Range(Selection, Selection.End(xlDown)).Select
                With Selection
                Selection.NumberFormat = "General"
                .Value = .Value
                End With
    regards
    raj
    Last edited by SamT; 03-14-2018 at 07:37 AM.

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    No patterns, can't loop.
    With Range("C:D")
      .NumberFormat = "General"
      .Value = .Value
     End With
    
    With Range("F:F")
      .NumberFormat = "General"
      .Value = .Value
     End With
    
    'Etc
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Tutor MINCUS1308's Avatar
    Joined
    Jun 2014
    Location
    UNDER MY DESK
    Posts
    254
    If you end up with a pattern or different cases or if you must loop, you could use an array or just a simple For loop.
    But if not, Id just go with SamT's method.

    Sub TEST()
         MyArr = Array("C", "D", "F", "L", "P", "T", "V", "W")
         
         For Each Element In MyArr
              Select Case Element
                   Case "C", "D", "F", "L", "P", "T", "V", "W"
                        With Columns(Element)
                             .NumberFormat = "General"
                             .Value = .Value
                        End With
                   'CASE          'IF YOU HAD OTHER CASES YOU COULD LIST THEM HERE
                        'AND PUT WHAT TO DO IN THOSE CASES HERE
                   'Case Else     'OR IF ALL OTHER CASES ARE THE SAME YOU COULD USE A CASE ELSE STATEMENT
                        'AND PUT WHAT TO DO IN ALL UNLISTED CASES HERE
              End Select
         Next Element
    End Sub
    - I HAVE NO IDEA WHAT I'M DOING

  4. #4
    thanks

Posting Permissions

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