ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   develop an if then else loop in excell that follows cursor moves (https://www.excelbanter.com/excel-programming/354313-develop-if-then-else-loop-excell-follows-cursor-moves.html)

Singforyou1954

develop an if then else loop in excell that follows cursor moves
 
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

Rogerio Takejame

develop an if then else loop in excell that follows cursor moves
 
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

--
Rogerio Takejame
Americana - Sao Paulo - Brazil


"Singforyou1954" wrote:

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



All times are GMT +1. The time now is 10:10 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com