PDA

View Full Version : [SOLVED:] How to set loop for selecting columns and converting numbers stored as text



rajkumar
03-14-2018, 02:14 AM
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

SamT
03-14-2018, 07:42 AM
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

MINCUS1308
03-14-2018, 08:35 AM
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

rajkumar
03-15-2018, 07:49 PM
thanks