LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default How can i make a macro run all sheets ?

Sub testme()
Dim myCell As Range
Dim myRng As Range
Dim DestCell As Range
Dim myWord As String
Dim wksht As Worksheet

myWord = "house"
For Each wksht In ActiveWorkbook.Sheets
With wksht
Set myRng = .Range("A1", .Cells(.Rows.Count, "A").End(xlUp))
Set DestCell = .Range("C1")
End With

For Each myCell In myRng.Cells
With myCell
If LCase(.Value) = LCase(myWord) Then
DestCell.Value = .Value & .Offset(0, 1).Value
Set DestCell = DestCell.Offset(1, 0)
End If
End With
Next myCell
Next wksht

End Sub


Gord Dibben MS Excel MVP

On Mon, 16 Nov 2009 15:35:23 +0000, andrei
wrote:


Actually i have this macro . It concatenates rows if given keyword is
found in A column and puts result in C column . That chages should i do
to run all sheets once ? Now i have to change the name of the sheet
every time i need to run macro



Code:
--------------------

Sub testme()
Dim myCell As Range
Dim myRng As Range
Dim DestCell As Range
Dim myWord As String

myWord = "house"

With Worksheets("Sheet1")
Set myRng = .Range("A1", .Cells(.Rows.Count, "A").End(xlUp))
Set DestCell = .Range("C1")
End With

For Each myCell In myRng.Cells
With myCell
If LCase(.Value) = LCase(myWord) Then
DestCell.Value = .Value & .Offset(0, 1).Value
Set DestCell = DestCell.Offset(1, 0)
End If
End With
Next myCell

End Sub

--------------------


 
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
Macro to Select All Sheets and Make Change to Footer Karin Excel Discussion (Misc queries) 2 September 20th 08 10:01 PM
Make macro available to all sheets Bill_S Excel Discussion (Misc queries) 3 April 10th 08 07:55 PM
Make global Macro/Add-in for all active Workbooks/Sheets SunRace Excel Programming 6 January 28th 08 12:40 PM
Is it possible to make an excel macro to work with all sheets? Mr. Pie Excel Programming 10 September 3rd 07 11:46 PM
how do you make macro run across protected sheets ace Excel Discussion (Misc queries) 1 April 13th 05 09:00 AM


All times are GMT +1. The time now is 09:41 PM.

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"