How to format column to number format in Excel sheet?

后端 未结 3 539
终归单人心
终归单人心 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
    

提交回复
热议问题