Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / December 2006

Tip: Looking for answers? Try searching our database.

Macro help please.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
owain@tractionkiting.co.uk - 06 Dec 2006 12:56 GMT
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.
Robert Bruce - 06 Dec 2006 13:17 GMT
Roedd <<owain@tractionkiting.co.uk>> wedi ysgrifennu:

See my edit inline:

> Hi!
> I am currently writing a macro for Excel and I have hit a problem.
[quoted text clipped - 7 lines]
>         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
[quoted text clipped - 12 lines]
> Thanks,
> Owain.

Rob
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.