J
JimFor
Hi,
I'm writing a program to manipulate some data on a spreadsheet and keep getting
errors in the looping section. The program keeps telling me it can't find part
of the the, for lack of a better term, looping instruction. Errors indicate I
have "something" without "something else." No matter what kind of looping
code I wrote, I keep getting the same kind of error.
Here is an example of what I am trying to do. I am comparing the values of
two cells in the same row. If the value of the cell in the second column of
the row equels zero, put the value found in the cell in the first column into
the cell found in the second column If the value of the cell in the second
column is not a zero, leave it along and go down one row and repeat the
procedure untill all the cells are examined Like I said, I have tried several
approaches. Here is an example of my simple For...Next loop test program which
looks at only four cells. I'll expand it once I get it to work. Can tell me
what I am doing wrong? I have values in Cells (1,1) through Cells (2,2) I
have a zero in Cell (2,1). When I run this program, I get a "Next without For"
error message.
Public Sub Same()
'Create variables to hold two numbers
Dim Input1 As Double
Dim Input2 As Double
'Create Count Variable
Dim Count As Double
'Set Count
For Count = 1 To 2
<======== But I do have a "For" in the program.
'Check cell valules
Input1 = Sheet1.Cells(1, Count)
Input2 = Sheet1.Cells(2, Count)
'Compare/change cell contents
If Input2 = 0 Then
Input2 = Input1
Else
Input2 = Input2
Next Count
End Sub
But obviously I am doing something wrong. And it applies to many different
kinds of loops. Once I understand this it will help me in writing future
programs.
Thanks
I'm writing a program to manipulate some data on a spreadsheet and keep getting
errors in the looping section. The program keeps telling me it can't find part
of the the, for lack of a better term, looping instruction. Errors indicate I
have "something" without "something else." No matter what kind of looping
code I wrote, I keep getting the same kind of error.
Here is an example of what I am trying to do. I am comparing the values of
two cells in the same row. If the value of the cell in the second column of
the row equels zero, put the value found in the cell in the first column into
the cell found in the second column If the value of the cell in the second
column is not a zero, leave it along and go down one row and repeat the
procedure untill all the cells are examined Like I said, I have tried several
approaches. Here is an example of my simple For...Next loop test program which
looks at only four cells. I'll expand it once I get it to work. Can tell me
what I am doing wrong? I have values in Cells (1,1) through Cells (2,2) I
have a zero in Cell (2,1). When I run this program, I get a "Next without For"
error message.
Public Sub Same()
'Create variables to hold two numbers
Dim Input1 As Double
Dim Input2 As Double
'Create Count Variable
Dim Count As Double
'Set Count
For Count = 1 To 2
<======== But I do have a "For" in the program.
'Check cell valules
Input1 = Sheet1.Cells(1, Count)
Input2 = Sheet1.Cells(2, Count)
'Compare/change cell contents
If Input2 = 0 Then
Input2 = Input1
Else
Input2 = Input2
Next Count
End Sub
But obviously I am doing something wrong. And it applies to many different
kinds of loops. Once I understand this it will help me in writing future
programs.
Thanks