How to format column to number format in Excel sheet?

后端 未结 3 483
终归单人心
终归单人心 2020-12-19 04:41

Below is the VBA code. Sheet2 contains all of the values in general format. After running the code, values in column \'C\' of Sheet3 contain exponential values for numbers

相关标签:
3条回答
  • 2020-12-19 05:04

    If your 13 digit "number" is really text, that is you don't intend to do any math on it, you can precede it with an apostrophe

    Sheet3.Range("c" & k).Value = "'" & Sheet2.Range("c" & i).Value
    

    But I don't see how a 13 digit number would ever get past the If statement because it would always be greater than 1000. Here's an alternate version

    Sub CommandClick()
    
        Dim rCell As Range
        Dim rNext As Range
    
        For Each rCell In Sheet2.Range("C1:C30000").Cells
            If rCell.Value >= 100 And rCell.Value < 1000 Then
                Set rNext = Sheet3.Cells(Sheet3.Rows.Count, 1).End(xlUp).Offset(1, 0)
                rNext.Resize(1, 3).Value = rCell.Offset(0, -2).Resize(1, 3).Value
            End If
        Next rCell
    
    End Sub
    
    0 讨论(0)
  • 2020-12-19 05:18

    Sorry to bump an old question but the answer is to count the character length of the cell and not its value.

    CellCount = Cells(Row, 10).Value
    If Len(CellCount) <= "13" Then
    'do something
    End If
    

    hope that helps. Cheers

    0 讨论(0)
  • 2020-12-19 05:19

    This will format column A as text, B as General, C as a number.

    Sub formatColumns()
     Columns(1).NumberFormat = "@"
     Columns(2).NumberFormat = "General"
     Columns(3).NumberFormat = "0"
    End Sub
    
    0 讨论(0)
提交回复
热议问题