Changing #N/A values in Excel to last non-error value in the spreadsheet

送分小仙女□ 提交于 2021-02-10 23:19:59

问题


I have a set of values that look like this:

Time        DataSet1        DataSet2
00:10:00    15              27
00:20:00    #N/A            25
00:30:00    33              45
00:40:00    #N/A            #N/A
00:50:00    #N/A            25
01:00:00    #N/A            12

Now, I want to fill all #N/A values with the previous valid value in the table. For example: the value for DataSet1 at 00:40:00, 00:50:00 and 01:00:00 should be 33. How does one do that?


回答1:


Select the area you want to fix and run this macro:

Sub FixData()
    Dim r As Range
    For Each r In Selection
        If r.Text = "#N/A" Then
            r.Value = r.Offset(-1, 0).Value
        End If
    Next
End Sub

For example, before:

enter image description here

and after:

enter image description here




回答2:


This should work for you:

=IF(ISERROR(<yourformulahere>),A1,<yourformulahere>)

Autofill from A2 to your last row.

Will only work if yourformula is "autofillable". (:

https://support.google.com/docs/answer/3093349




回答3:


  1. Select A1 then tap F5 and when the GoTo dialog appears, click Special.

  2. Check Formulas and uncheck everything but Errors.

  3. Click OK.
  4. Type = then and finalize with Ctrl+Enter.

The errors should be converted to the value above.




回答4:


Just in case you prefer a macro-way:

Dim val As String
Dim col_to_check As Long, cnt As Long

col_to_check = 2 ' We check the 2nd column
cnt = 1 ' We'll use it to check rows below

For i = 1 To ActiveSheet.UsedRange.Rows.Count
 If IsError(Cells(i, col_to_check)) Then
   val = Cells(i - 1, col_to_check)
   Cells(i, col_to_check) = val
   While IsError(Cells(i + cnt, col_to_check))
     Cells(i + cnt, col_to_check) = val
     cnt = cnt + 1
   Wend
 End If
 i = i + cnt - 1
 cnt = 1
Next i



回答5:


We need to fill in "#N/A" cells with a formula =above cell address.

  1. CTRL+F
  2. Type #N/A
  3. Click Find All
  4. Highlight all with mouse as picture below.
  5. Click on one space above menu - see oval (do not close Find and Replace window)
  6. Start typing = and press Up key.
  7. Press CTRL+Enter
  8. Copy and paste all as text, to get rid of formulas.

enter image description here



来源:https://stackoverflow.com/questions/28879818/changing-n-a-values-in-excel-to-last-non-error-value-in-the-spreadsheet

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!