View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Don Don is offline
external usenet poster
 
Posts: 487
Default Excel 2003 Macro to add text to front of data in cell

Rocky,

Here's a simple code that will open up a couple of input boxes that let you
select which column you want to examine and what you want to search for.
However, this is case sensitive and I've played with it for some time and
can't get it to be case insensitive, but I'm sure someone will jump in with
that solution....

Option Explicit
Sub Macro4()

Dim LastRow As Integer
Dim i As Integer
Dim x As String
Dim Col As String

Col = InputBox("What Column Do You Wish To Start In?")
With ActiveSheet
LastRow = .Cells(.Rows.Count, Col).End(xlUp).Row
End With
x = InputBox("Search For:")
For i = 1 To LastRow

If Range(Col & i).Value = x Then
Range(Col & i).Select
If MsgBox("Is This One To Addend?", vbYesNo + vbInformation) = vbNo Then
Range(Col & i).Offset(0, 1) = ""
Else
Range(Col & i).Offset(0, 1) = "47-" & Range(Col & i)
End If
End If
Next

I'm also fairly new to this coding so there most likely is a much simpler
way.....but, HTH...

Don


"Rocky Lane" wrote:

I have an extremely simple task to perform manually. But to change over
10,000 cells - not! Everybody knows Excel allows you to write simple VBA
macros to do things like this.

OK ... I'm a dummy ... I give up. I could have manually done the changes in
the time I've wasted trying to create a working macro solution.

I have a 47,000 + row spreadsheet with 2 columns (not column A & B). After
manually selecting the current cell location, I want to start the macro. In
text cells in the first column, I want to search down the column looking for
the letters RCA. Case is not important. If found, I want to pause the macro
to allow me to decide if what the macro has found is acceptable.
If it is, I want to press the "y" key to add 47- to the front of data in the
cell to the right (second column) of the found cell in the first column. For
example if the second column cell contained 4862, after pressing the "y" key,
the cell would contain 47-4862 and the current cell location would move left
to the first column to continue searching for RCA.
If it is not acceptable, I want to press the "n" key and have the macro
continue searching for RCA from the current cell location down the first
column.

Help!

Thanks.