[VBA]How to delete all useless 0 in the end of a column -


my purpose needs find out time gap between every row. should go 1 second 1 second, see until 11:40, there large one. example, time a3-a2=b1. solved problem already, code following.

it runs ok, in end of column b, there long list of 00:00:00. want match last number of column b column a, means column b , should have same length. thousands of 00:00:00 in end.

sub calculatetimegap()    columns("b:b").insert shift:=xltoright, copyorigin:=xlformatfromleftorabove range("a1").value = "time"  columns("a:a").numberformat = "hh:mm:ss" columns("b:b").formula = "=a2-a1" range("b1").value = "time difference(s)" columns("b:b").numberformat = "hh:mm:ss"  lrow = cells(rows.count, 1).end(xlup).row end sub   time      time difference(s) 11:28:37    00:00:01 11:28:38    00:00:01 11:28:39    00:00:01 11:28:40    00:11:35 11:40:15    00:00:01 11:40:16    00:00:01 11:40:17    00:00:01 11:40:18    00:00:01             00:00:00             00:00:00             00:00:00             00:00:00             00:00:00             00:00:00             00:00:00             00:00:00             00:00:00             00:00:00 

i tried add code inside delete 00:00:00 didn't work.

if range("b").value = "00:00:00"     'range("b").value.delete end if 

i think better use loop in here

 dim lr,i double      lr=application.count(range("a:a"))     i=1 lr step 1      cells(i,2).value=cells(i+1,1).value-cells(i,1).value     next 

and alternative preserve code be:

sub calculatetimegap()    columns("b:b").insert shift:=xltoright, copyorigin:=xlformatfromleftorabove range("a1").value = "time"  dim lr variant  lr=application.count(range("a:a")) columns("a:a").numberformat = "hh:mm:ss" columns("b2:b"&lr).formula = "=a2-a1" range("b1").value = "time difference(s)" columns("b:b").numberformat = "hh:mm:ss"  lrow = cells(rows.count, 1).end(xlup).row end sub 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -