Solved

Evaluating if a cell begins with a specific character

Posted on 2007-04-11
5
1,077 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 18888757
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
ID: 18889094
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
ID: 18889176
You need:
If Left$(Plan2.Range("A" & line),1) = "#" Then

HTH
Rory
0
 

Author Comment

by:luizblink182
ID: 18889220
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
ID: 18890801
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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

696 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