title: How to number format only certain cells that contain data using VBA
body: <p>The following code reads lines from a csv file and reformats row headings.  I hope I can articulate this, but I'd like to format cells to two decimals in rows below headings in which the <code>vct_FEMAP_Results()</code> function returns a value.</p>
  
  <hr>
  
  <p><strong>Example:</strong> </p>
  
  <pre><code>   ID    "CSys ID"   "Set ID"     Plate Top VM Stress     Plate Bot VM Stress  
   ------ ----------- ---------- ----------------------- ---------------------- 
    4591         0         20              229.9488               244.8103  
    4592         0         20              323.5026               315.1129
  </code></pre>
  
  <p>I'm trying to format the cells containing the decimals without affecting the data in column headings <code>ID</code>, <code>CSys ID</code>, or <code>Set ID</code>.  The code below formats all columns to <strong>2 decimals</strong>.  Not sure why.</p>
  
  <pre><code>Sub cmdOpen_Click()
      Dim wrdArray() As String, txtstrm As TextStream, line As String
      Dim wrd As Variant, myWrd As String
      Dim col As Long, colCount As Long
      Dim count As Long
      Dim row As Long, temp As Long
  
      Dim str As String, regex As RegExp
      Dim matches As MatchCollection, lineMatch As match, wrdMatch As match
      Dim i As Long, j As Long, x As Long
      Dim strPath As String, strLine As String
  
      Set regex = New RegExp
      regex.Pattern = "\d+"
      regex.Global = True
  
      'Remove Filters and Add Custom Filters
      Call Application.FileDialog(msoFileDialogOpen).Filters.Clear
      Call Application.FileDialog(msoFileDialogOpen).Filters.Add("Text Files", "*.txt")
      Call Application.FileDialog(msoFileDialogOpen).Filters.Add("Dat Files", "*.dat")
      Call Application.FileDialog(msoFileDialogOpen).Filters.Add("Comma Delimited Files", "*.csv")
  
      'only allow the user to select one file
      Application.FileDialog(msoFileDialogOpen).AllowMultiSelect = False
  
      'make the file dialog visible to the user
      intChoice = Application.FileDialog(msoFileDialogOpen).Show
  
      'determine what choice the user made
      If intChoice &lt;&gt; 0 Then
  
      'get the file path selected by the user
      strPath = Application.FileDialog(msoFileDialogOpen).SelectedItems(1)
  
      End If
  '------------------------------------------------------------
  
       If strPath &lt;&gt; "" Then
          Set txtstrm = FSO.OpenTextFile(strPath)
      Else
          Exit Sub
      End If
  
      row = 1
      Do Until txtstrm.AtEndOfStream
        line = txtstrm.ReadLine
  
        x = 1
        col = 1
        count = 0
  
        wrdArray() = Split(line, ",")
  
        For Each wrd In wrdArray()
          count = count + 1
          myWrd = wrd
  
          ActiveSheet.Cells(row, col) = wrd
          col = col + 1
        Next wrd
  
        If (row = 1) Then
          For i = 0 To count - 1
              Set matches = regex.Execute(wrdArray(i))
              For Each wrdMatch In matches
                  If wrdMatch Then
                      ActiveSheet.Cells(1, i + 1) = vct_FEMAP_Results(wrdMatch.Value)
                      x = x + 1
                  End If
              Next
          Next i
        End If
  
      row = row + 1
      Loop
  
      txtstrm.Close
  
      For i = 1 To row - 1
          For j = x To col - 1
              ActiveSheet.Cells(i, j).NumberFormat = "0.00"
          Next j
      Next i
  
  End Sub
  </code></pre>