Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
I have an excel sheet with cells mostly filled by numeric values. But in each row some cells wont have a value but a "not available number" (NaN) instead. So what I'm looking for is a macro that checks if a cell contains a NaN. If that's the case go one (or more) column(s) to the right in this row until there is the next numeric value and copy/paste this value to the cell where the NaN has been found in the first place. Do this for all cells in the row, then jump one row down and start over again. input: 320 300 NaN 310 NaN 400 380 NaN NaN 370 330 308 NaN 313 NaN 407 379 NaN NaN 378 .... desired output: 320 330 310 400 380 370 330 308 313 407 479 378 ..... thanks for your help Stefan |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try this (but make sure you have backed up you data!):
Sub removeNan() With Worksheets("Sheet1") lastrow = .Cells(Rows.Count, "A").End(xlUp).Row For r = 2 To lastrow lastcol = .Cells(r, Columns.Count).End(xlToLeft).Column For col = lastcol To 1 Step -1 If .Cells(r, col) = "NaN" Then .Cells(r, col).Delete Shift:=xlToLeft Next col Next r End With End Sub HTH " wrote: Hi I have an excel sheet with cells mostly filled by numeric values. But in each row some cells wont have a value but a "not available number" (NaN) instead. So what I'm looking for is a macro that checks if a cell contains a NaN. If that's the case go one (or more) column(s) to the right in this row until there is the next numeric value and copy/paste this value to the cell where the NaN has been found in the first place. Do this for all cells in the row, then jump one row down and start over again. input: 320 300 NaN 310 NaN 400 380 NaN NaN 370 330 308 NaN 313 NaN 407 379 NaN NaN 378 .... desired output: 320 330 310 400 380 370 330 308 313 407 479 378 ..... thanks for your help Stefan |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Works great.
Thanks alot for your fast reply and the helpful code. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks for feedback.
" wrote: Hi I have an excel sheet with cells mostly filled by numeric values. But in each row some cells wont have a value but a "not available number" (NaN) instead. So what I'm looking for is a macro that checks if a cell contains a NaN. If that's the case go one (or more) column(s) to the right in this row until there is the next numeric value and copy/paste this value to the cell where the NaN has been found in the first place. Do this for all cells in the row, then jump one row down and start over again. input: 320 300 NaN 310 NaN 400 380 NaN NaN 370 330 308 NaN 313 NaN 407 379 NaN NaN 378 .... desired output: 320 330 310 400 380 370 330 308 313 407 479 378 ..... thanks for your help Stefan |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Code to copy the formulae of one cell to all the cell in the rangewith the specific cell and columnnumber changing Options | Excel Discussion (Misc queries) | |||
Code to copy the formulae of one cell to all the cell in the rangewith the specific cell and columnnumber changing | Excel Discussion (Misc queries) | |||
How can I copy a value from a cell and paste it into another cell while adding it to the previous value in that cell | Excel Worksheet Functions | |||
VBA to copy to empty cell directly below a cell when analogous cells in different column have same value as each other? | Excel Programming | |||
VBA to copy to empty cell directly below a cell when analogous cells in different column have same value as each other? | Excel Programming |