Macro help please.

O

owain

Hi!
I am currently writing a macro for Excel and I have hit a problem.

Here is my working Macro code.

Sub dialight()
Range("B1").Select
ActiveCell.Offset(1, 0).Select
Do While ActiveCell.Value > ""
If ActiveCell.Value = "DIALIGHT" Then
ActiveCell.Offset(0, -1).Select
ActiveCell.Value = ActiveCell.Value + "F"
ActiveCell.Offset(1, 1).Select
Else
ActiveCell.Offset(1, 0).Select
End If
Loop
End Sub

This works perfectly but the problem I have is if someone runs the
Macro twice, the ActiveCell.value will end of having 2 Fs at the end of
it which will cause huge problems further down the line.

How can I can check to see if the ActiveCell.Value already has an F at
the end of it?

Thanks,
Owain.
 
R

Robert Bruce

Roedd <<[email protected]>> wedi ysgrifennu:

See my edit inline:
Hi!
I am currently writing a macro for Excel and I have hit a problem.

Here is my working Macro code.

Sub dialight()
Range("B1").Select
ActiveCell.Offset(1, 0).Select
Do While ActiveCell.Value > ""
If ActiveCell.Value = "DIALIGHT" Then
ActiveCell.Offset(0, -1).Select
' Check for empty cell
If IsEmpty(ActiveCell) Then
ActiveCell.Value = "F"
Else
If Not Right(ActiveCell.Value, 1) = "F" Then
ActiveCell.Value = ActiveCell.Value + "F"
End If
End If
ActiveCell.Offset(1, 1).Select
Else
ActiveCell.Offset(1, 0).Select
End If
Loop
End Sub

This works perfectly but the problem I have is if someone runs the
Macro twice, the ActiveCell.value will end of having 2 Fs at the end
of it which will cause huge problems further down the line.

How can I can check to see if the ActiveCell.Value already has an F at
the end of it?

Thanks,
Owain.

Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top