index > Visual Basic for Applications (VBA) > Help finding the next similar cell and inserting rows

Help finding the next similar cell and inserting rows


I am working on an Excel worksheet that has the word "TOUR" listed throughout the spreadsheet. How can I find the next "TOUR" and insert rows to make sure it is in the row I want it in?


Example:

DBCS #33
Help TW

Hi,

You should look to use the Selection.Find method to perform your search.... this code should do the search and find all TOURS in the list but it doesn't do anything else.


'select the whole range to search, in this case column A
Columns("A:A").Select

'the tour found, stored as a range
Dim FoundTour As Range

'do an inital search and find the first tour in column A
Set FoundTour = Selection.Find(What:="TOUR", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)

'if tour was found then
If Not FoundTour Is Nothing Then

'store it's address which is used to determine if the search has been completed
Dim firstAddress As String
firstAddress = FoundTour.Address

Do
'find the next tour after the current found tour
Set FoundTour = Selection.FindNext(FoundTour)

'continue the search until tour is no longer found or until the search reaches the starting address
'of the first found tour
Loop While Not FoundTour Is Nothing And FoundTour.Address <> firstAddress

End If




www.dsmyth.net/blog
Derek Smyth
Thanks for the information, but I need to know how to look for Tour and verify that it is in a certain cell. If it is not in a certain cell, I need to insert rows until it is in the cell that I want.
Help TW

reply 3

You can use google to search for other answers

 

More Articles

• Access and VBA application in the mdb file
• dbgrid link listbox help !!!
• How do I write this!!
• Run-time error '1004' in import macro
• Printing by using a vba code
• transaction processing in an Access app?
• Excel Unprotect WorkSheet problem in Excel 97
• how to connect two locations to better communication
• excel formula
• My mini Utility_Move class, please have some suggestions.
Welcome to Bokebb   New Update   Joins the collection  
 

New Articles

• Moving Mail Items from Outlook through V
• Excel FTP using msinet.ocx - PROBLEM
• Excel Chart: How to change chart data so
• Web services reference not displayed
• goal seek
• access populate combo box help needed
• Does the VBA save word as XML???
• What is an error 400?
• Outlook automation with encrypted signed
• XSL applied with VBA
• Can not generate Proxy class for web ser
• Querying ActiveDirectory with VBA in Excel
• Export excel sheet as text file with mac
• call addin's userform
• Modify .PRJ File

Hot Articles

• How do I write this!!
• web query failure, On Error didn't work
• Runtime Error '2001'
• VBA for Outlook: How to create a Hyperli
• How do I disable the Windows Toolbar?
• File name - VBA for powerpoint
• Application Error
• Wanted - VBA Developer Banking Zurich
• Creating Logon in MS Access
• fast search
• extract office file's title into excel
• am i have mak mistake?
• Problem with XP SP2
• Using a single variable to get a combine
• precisely position embedded charts in wo

Recommend Articles

• Automatic BCC from Outlook (VBA)
• macro in .xml
• Need help creating trigger animation wit
• Change format of cells
• Application.FileSearch in Excel 2007
• VB writing data to an Excel file
• VBA within Excel_revised
• download a file via internet and save it
• Microsoft Document Image Printer - MODI
• Unpredictable (as yet) problem with Date
• VBA source code
• Help: How can I deploy my VBA?
• Saving all individual worksheets in a wo
• Scripting
• Selecting Data By....