Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default VBA Search Workbook Question (Excel 2007)


I have been using this particular macro for 12 years, including
several months since I got Excel 2007 on my work computer. But
something happened today that had me puzzled till I stepped through
the macro and pinpointed the problem.

My macro (snippet below) removes dashes and blanks from column B.

Sub ReplaceStuff()
Columns("B:B").Select
Selection.Replace What:="-", Replacement:="", LookAt:=xlPart
Selection.Replace What:=" ", Replacement:="", LookAt:=xlPart
End Sub

Today, when I ran the macro, I discovered that it removed the dashes
and blanks from the entire sheet (only a one-sheet workbook) instead
of just the Selection. Then I remembered that a while back I was
trying to create a macro to search an entire workbook but the code
generated from the macro recorder didn't seem to have anything to
specify the Sheet or the Workbook. Also, I had done a search earlier
today and manually change the Within option to Workbook. Just as I
suspected, when I manually changed the Within option back to Sheet, my
macro functioned properly.

I have two questions. Maybe they have the same answer.

Is there a VBA way to restrict a search to the Selection regardless
what the last choice was in the Find dialog?

Is there a VBA way to search an entire workbook regardless what the
last choice was in the Find dialog?

Thanks,
Francis (TheExcelAddict.com)


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Search Workbook Question (Excel 2007) Francis[_6_] Excel Programming 0 June 3rd 09 04:22 PM
How do I do a File Search in Word or Excel 2007? CatsR4jae Excel Discussion (Misc queries) 2 May 11th 09 04:15 PM
Excel 2007 - Workbook.Open Question Barb Reinhardt Excel Programming 4 October 1st 08 09:06 PM
Excel search in cell - ecxel 2007 Savannah Excel Worksheet Functions 0 February 12th 08 08:34 PM
SEARCH AND REPLACE (in Excel 2007, beta) Rebecca Excel Programming 2 June 3rd 06 09:39 AM


All times are GMT +1. The time now is 09:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"