Solved

Evaluating if a cell begins with a specific character

Posted on 2007-04-11
5
1,064 Views
Last Modified: 2013-12-25
I have a list with several values in a excel sheet.

All I need to do is create a macro that checks if the cell begins with #, and if it does insert a "=" sign on row B.

If the "=" sign is already in roll B, do nothing.

How can I do that? Thank you very much!
0
Comment
Question by:luizblink182
  • 2
  • 2
5 Comments
 
LVL 92

Expert Comment

by:Patrick Matthews
Comment Utility
Row B?

This sub will go through the currently selected range and make the change:

Sub foo()

    Dim cel As Range
   
    For Each cel In Selection.Cells
        If Left(cel, 1) = "#" Then cel = "=" & Mid(cel, 2)
    Next
   
End Sub
0
 

Author Comment

by:luizblink182
Comment Utility
Yeah I meant column B :-D

I didn't understand your code, what I was thinking of was something like this:

   For line = 1 To 10
       If Plan2.Range("A" & line) = (THIS IS THE PART I DON'T KNOW HOW TO DO) "BEGINS WITH #" Then
            Plan2.Range("B" & line).Value = "="
       End If
   Next

the rest I can do =)
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 250 total points
Comment Utility
You need:
If Left$(Plan2.Range("A" & line),1) = "#" Then

HTH
Rory
0
 

Author Comment

by:luizblink182
Comment Utility
That's it rorya =)

Thank you very much. Is there anyway somebody would just help me out exporting everything to a text file (without any tabs) using a macro?
0
 
LVL 92

Expert Comment

by:Patrick Matthews
Comment Utility
For exporting delimited text files, I like using this little add-in I created:

http://vbaexpress.com/kb/getarticle.php?kb_id=805
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now