Macro/VBA Help

cmclyne

New Member
Joined
Dec 28, 2009
Messages
6
I have a spreadsheet with multiple tabs. I want to have one master tab read through columns in other tabs, and if it says a certain word (e.g., Secondary) then it copies that row and pastes it in the master tab. Is this possible, if so how. Thanks.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Also here is a sub that I wrote that might work for you:

Sub CopyRowsToMaster()

Dim myws As Worksheet, Masterws As Worksheet, mybook As Workbook
Dim bFound As Boolean
Dim LastRow As Integer, LastColumn As Integer, ColumnCounter As Integer, RowCounter As Integer

Set Masterws = ActiveWorkbook.Worksheets("master")
Set mybook = ActiveWorkbook

'First loop through the work sheets
For Each myws In mybook.Worksheets

'Check worksheet name is not "Master"
If myws.Name <> "master" Then
'Get the last column
LastColumn = myws.Range("A1").SpecialCells(xlCellTypeLastCell).Column

'loop through columns
For ColumnCounter = 1 To LastColumn
'Get the last row in the column
LastRow = myws.Cells(myws.Rows.Count, ColumnCounter).End(xlUp).Row

'Finally loop through the rows of each column looking for the word "Secondary"
For RowCounter = 1 To LastRow
If myws.Cells(RowCounter, ColumnCounter) = "secondary" Then
'Found the word "Secondary" so Copy the row and past the row to master sheet
myws.Cells.Rows(RowCounter).Copy Destination:=Sheets("master").Range("A" & Rows.Count).End(xlUp).Offset(1)​
End If​
Next RowCounter
Next ColumnCounter​
End If​
Next myws

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,749
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top