Solved

Evaluating if a cell begins with a specific character

Posted on 2007-04-11
5
1,070 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
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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

777 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