moving cells to another column based on number of characters

G

Guest

I download a report each day that varies in length so my row count is
unknown. About 20 cells populate in column H that should be in column I.
Below is a sample. The correct information in Col H is normally 6
characters. The longer 13 character number belongs in Col I. As you can
see, the cell in column I is empty when the data is incorrectly in column H
on the same row. I'm not sure the best code to put in an existing macro for
the active sheet to move the cells in column H to column I when the text in
the cell is greater than 6. I'm grateful for any help you can give me.
H I

N430AF 0009119181112
N39D93 0000730756201
0000730756201
932257786
N38C72 979722772
N42C26 0001875221211
N3677D 0009650691112
 
G

Guest

Sub MoveValues()
Dim rng as Range, cell as Range
set rng = Range(cells(2,"H"),cells(rows.count,"H").end(xlup))
for each cell in rng
if len(cell) = 13 then
cell.offset(0,1).value = cell.value
cell.clearcontents
end if
next
End sub

test it on a copy of your data.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top