Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Every other
In the code below, I'm trying to write a row of 5 items to a new spreadsheet.
I have a feeling that I might be making this a bit more difficult than I have to. But what's happening is that the sub only writes every other item to the worksheet "Events" Why is it skipping items 2 and 4? Sub event_write(w, r_ind) With Worksheets("props 2") Set t_range = .Range(w.Offset(0, -4), w.Offset) End With ind = 1 For Each t In t_range If ind = 1 Or ind = 4 Then Worksheets("Events").Cells(r_ind, ind).Value = Format(t.Offset(0, ind - 1).Value, "hh:mm:ss") Else Worksheets("Events").Cells(r_ind, ind).Value = t.Offset(0, ind - 1).Value End If MsgBox t.Value ind = ind + 1 Next t End Sub David |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Every other
David,
It's not skipping them - it must be that the cells referred to are blank. You can see that by using this: For Each t In t_range If ind = 1 Or ind = 4 Then Worksheets("Events").Cells(r_ind, ind).Value = "test" ' _ Format(t.Offset(0, ind - 1).Value, "hh:mm:ss") Else Worksheets("Events").Cells(r_ind, ind).Value = "test" ' _ t.Offset(0, ind - 1).Value End If MsgBox t.Value ind = ind + 1 Next t HTH, Bernie MS Excel MVP "David Gerstman" wrote in message ... In the code below, I'm trying to write a row of 5 items to a new spreadsheet. I have a feeling that I might be making this a bit more difficult than I have to. But what's happening is that the sub only writes every other item to the worksheet "Events" Why is it skipping items 2 and 4? Sub event_write(w, r_ind) With Worksheets("props 2") Set t_range = .Range(w.Offset(0, -4), w.Offset) End With ind = 1 For Each t In t_range If ind = 1 Or ind = 4 Then Worksheets("Events").Cells(r_ind, ind).Value = Format(t.Offset(0, ind - 1).Value, "hh:mm:ss") Else Worksheets("Events").Cells(r_ind, ind).Value = t.Offset(0, ind - 1).Value End If MsgBox t.Value ind = ind + 1 Next t End Sub David |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Every other
Bernie,
I solved it by taking out the offset reference. For Each t In t_range If ind = 1 Or ind = 4 Then Worksheets("Events").Cells(r_ind, ind).Value = Format(t.Value, "hh:mm:ss") Else Worksheets("Events").Cells(r_ind, ind).Value = t.Value End If next t David "Bernie Deitrick" wrote: David, It's not skipping them - it must be that the cells referred to are blank. You can see that by using this: For Each t In t_range If ind = 1 Or ind = 4 Then Worksheets("Events").Cells(r_ind, ind).Value = "test" ' _ Format(t.Offset(0, ind - 1).Value, "hh:mm:ss") Else Worksheets("Events").Cells(r_ind, ind).Value = "test" ' _ t.Offset(0, ind - 1).Value End If MsgBox t.Value ind = ind + 1 Next t HTH, Bernie MS Excel MVP "David Gerstman" wrote in message ... In the code below, I'm trying to write a row of 5 items to a new spreadsheet. I have a feeling that I might be making this a bit more difficult than I have to. But what's happening is that the sub only writes every other item to the worksheet "Events" Why is it skipping items 2 and 4? Sub event_write(w, r_ind) With Worksheets("props 2") Set t_range = .Range(w.Offset(0, -4), w.Offset) End With ind = 1 For Each t In t_range If ind = 1 Or ind = 4 Then Worksheets("Events").Cells(r_ind, ind).Value = Format(t.Offset(0, ind - 1).Value, "hh:mm:ss") Else Worksheets("Events").Cells(r_ind, ind).Value = t.Offset(0, ind - 1).Value End If MsgBox t.Value ind = ind + 1 Next t End Sub David |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Every other
But the cells referred to are not blank.
For example the macro is reading 1 2 3 4 5 and writing out 1 3 5 (with no spaces in between) However when I did your test I got test test test test test David "Bernie Deitrick" wrote: David, It's not skipping them - it must be that the cells referred to are blank. You can see that by using this: For Each t In t_range If ind = 1 Or ind = 4 Then Worksheets("Events").Cells(r_ind, ind).Value = "test" ' _ Format(t.Offset(0, ind - 1).Value, "hh:mm:ss") Else Worksheets("Events").Cells(r_ind, ind).Value = "test" ' _ t.Offset(0, ind - 1).Value End If MsgBox t.Value ind = ind + 1 Next t HTH, Bernie MS Excel MVP "David Gerstman" wrote in message ... In the code below, I'm trying to write a row of 5 items to a new spreadsheet. I have a feeling that I might be making this a bit more difficult than I have to. But what's happening is that the sub only writes every other item to the worksheet "Events" Why is it skipping items 2 and 4? Sub event_write(w, r_ind) With Worksheets("props 2") Set t_range = .Range(w.Offset(0, -4), w.Offset) End With ind = 1 For Each t In t_range If ind = 1 Or ind = 4 Then Worksheets("Events").Cells(r_ind, ind).Value = Format(t.Offset(0, ind - 1).Value, "hh:mm:ss") Else Worksheets("Events").Cells(r_ind, ind).Value = t.Offset(0, ind - 1).Value End If MsgBox t.Value ind = ind + 1 Next t End Sub David |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|