bl79
Mechanical
- Jan 22, 2011
- 12
OK, I am having a lot of trouble utilizing loops and if statements. I have some experience with programming but for some reason writing these macros is killing me.
I just want to create a macro that will go through every single cell and check it to see if X is in that cell. If X is in the cell then change it to Y and continue to the next cell and if not then move to the next cell.
Ive tried several ways of doing this but none seem to work for me. Could someone help me out.
For example Ive tried to delete the #DIV/0! error(I know there are easier ways but I would like to come up with a general method as I described for other circumstances.
My several faulty codes:
Sub delete()
Do While n < 30
Do While i < 30
If Cells(i, n).Value = "#DIV/0!" Then [Cells(i,n).Value=""]
i = i = 1
Loop
n = n + 1
Loop
End Sub
Sub Macro1()
For n = 1 To n = 30
For i = 1 To i = 30
Cells(i, n).Select
If ActiveCell = "#DIV/0!" Then
ActiveCell.Value = ""
End If
Next i
Next n
End Sub
Again, I know there are more efficient ways but I see no reason why this wouldn't work. Clearly Im just a newb
I just want to create a macro that will go through every single cell and check it to see if X is in that cell. If X is in the cell then change it to Y and continue to the next cell and if not then move to the next cell.
Ive tried several ways of doing this but none seem to work for me. Could someone help me out.
For example Ive tried to delete the #DIV/0! error(I know there are easier ways but I would like to come up with a general method as I described for other circumstances.
My several faulty codes:
Sub delete()
Do While n < 30
Do While i < 30
If Cells(i, n).Value = "#DIV/0!" Then [Cells(i,n).Value=""]
i = i = 1
Loop
n = n + 1
Loop
End Sub
Sub Macro1()
For n = 1 To n = 30
For i = 1 To i = 30
Cells(i, n).Select
If ActiveCell = "#DIV/0!" Then
ActiveCell.Value = ""
End If
Next i
Next n
End Sub
Again, I know there are more efficient ways but I see no reason why this wouldn't work. Clearly Im just a newb