Thursday, December 13, 2012

Find Replace-Offset

I just finished this yesterday and Im very pleased with it.

The purpose is to Find every instance of a word in an entire workbook, and replace a cell X spaces to the right.

The code looks like this:

Sub findreplaceoffset()
Dim Stext As String
Dim Oset As Integer
Dim Rtext As String
Dim CheckVal As String
Dim ws As Worksheet
Dim result As Range

Stext = Application.InputBox("Type in the word you want to find")
Oset = Application.InputBox("Type in the Column offset to be replaced")
Rtext = Application.InputBox("Type in what you want replaced")

For Each ws In Application.ThisWorkbook.Sheets
ws.Activate
Range("A1").Activate
Do While CheckVal <> Rtext
On Error GoTo Skip:
   Set result = Cells.Find(What:=Stext, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False)
       
        If result Is Nothing Then
        GoTo Skip:
        End If
       
        result.Activate   
   
        CheckVal = result.Offset(0, Oset).Value
       
        result.Offset(0, Oset).Value = Rtext   
       
Loop
CheckVal = ""
Skip:
Next ws
End Sub


In this sample the workbook contains quotations with items and amounts.
You can now download the sample sheet that contains the macro and follow along.


Today lets suppose we need to change the price of all of the Apples in every sheet to $100
Run the macro and an input box request what word you want to find.
Type "Apples"



















Another input box requests the offset
Type: "1" as the pricing we want to replace is 1 space to the right of Apples
The last inpub box is the replacement value
Type:"100"

Now every ammount 1 cell to the right of apples has been changed.


Wednesday, December 12, 2012

File Hosting Test

I have been trying to find a place to host the Excel files so I can make them available for download.
Sometimes just a blog with pictures and descriptions isnt enough.


Click the link below to download a spreadsheet with the Count Color macro from my previous Post
File Test (Count-Color - Excel Macro)

This hosting is from Google Sites.