Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 13th, 2006, 01:25 PM
Registered User
 
Join Date: Mar 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to utalwalk
Default Search/Update in multiple worksheets VBA code help

Hi folks:

I'm looking for some code help in Excel VBA to write a subroutine to lookup a text string in a defined range of cells say A4:AZ4 in all 3 sheets. My requirement is that if the string is not found then it should write that content in sheet 4 with a comment. However, if found then the code would update a column next to the found cell(row,col) with a text string.

Has anyone tried something simillar? If so, would you like to share your ideas?

Reply With Quote
  #2 (permalink)  
Old April 19th, 2006, 04:42 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: London, , United Kingdom.
Posts: 173
Thanks: 0
Thanked 3 Times in 3 Posts
Default

This seems to do the job:

Code:
Public Sub Main()

Dim strSearchRange As String
Dim shSearchSheets As New Collection
Dim SearchSheet As Worksheet
Dim OutSheet As Worksheet
Dim strToFind As String
Dim Cell As Range

    strSearchRange = "A4:AZ4"

    shSearchSheets.Add Item:=ThisWorkbook.Sheets("Sheet1")
    shSearchSheets.Add Item:=ThisWorkbook.Sheets("Sheet2")
    shSearchSheets.Add Item:=ThisWorkbook.Sheets("Sheet3")

    Set OutSheet = ThisWorkbook.Sheets("Sheet4")
    strToFind = "Test"

    For Each SearchSheet In shSearchSheets

        Set Cell = SearchSheet.Range(strSearchRange).Find(strToFind)

        If Not Cell Is Nothing Then
            SearchSheet.Columns(Cell.Column).Insert Shift:=xlRight
            Cell.Offset(0, -1).Value = "Found it!"
            Exit Sub
        End If

    Next SearchSheet

    OutSheet.Cells(1, 1).Value = strToFind
    OutSheet.Cells(1, 1).ClearComments
    With OutSheet.Cells(1, 1).AddComment
        .Visible = False
        .Text Text:="Couldn't find this"
    End With

End Sub
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create an Excel Spread with multiple worksheets hewstone999 Access VBA 1 March 7th, 2008 08:21 AM
VBA code to Search All Text Fields on a form dezmond2 BOOK: Access 2007 VBA Programmer's Reference ISBN: 978-0-470-04703-3 1 July 7th, 2007 11:58 AM
updating multiple worksheets at once bcastello Excel VBA 3 October 17th, 2006 11:46 PM
Splitting Excel file into Multiple Worksheets tvschalapathirao Dreamweaver (all versions) 3 May 16th, 2005 02:16 AM
Multiple Joins in Multiple Table Search query pookster Access 4 September 23rd, 2004 03:04 PM



All times are GMT -4. The time now is 08:01 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.