develop an if then else loop in excell that follows cursor moves

G

Guest

I need to manage data that I pull in from an SQL data base where the collumn
that is supposed to hold dates is a number field. I would like to be able to
write a macro to do a loop that goes down the colloumn and says if cell < 0
then (cursor movement**end (to get cursor to the far right in the cell) left
arrow, left arrow insert / left arrow, left arrow, left arrow, insert /) else
end. I cannot seem to write one that does not copy the cell above and I am
very rusty in vba. Thank you for your help
 
G

Guest

I'm not sure if I understood what you mean with (cursor movement**end (to get
cursor to the far right in the cell) left arrow, left arrow insert / left
arrow, left arrow, left arrow, insert /), but I supose you want to edit the
number to represent a date, right?
let's supose your date is in cell A2.
If your column is a number like 02242006 witch means 02/24/2006 then we can
convert it to a text using:
cells("A2") = format(left(cells("A2"), 2), "00") & "/" &
format(mid(cells("A2"), 3,2),"00") & "/" & format(right(cells("A2"), 4),
"0000")

within a loop it will look like:
r = 2
'your initial row
do while cells(r,1)>0
cells(r,1) = format(left(cells(r,1), 2), "00") & "/" &
format(mid(cells(r,1), 3,2),"00") & "/" & format(right(cells(r,1), 4), "0000")
r=r+1
loop
 

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