#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 132
Default Macro question

Hi:

I am having difficulty writing a procedure which copy one row from sheet 1
in the first row available in sheet 2.
Part of the loop procedure is below.

Do
If ActiveCell.Value = "TOR" Then
ActiveCell.EntireRow.Copy
Sheets("Sheet2"). (paste in column A in the first row available)

Could anyone help me please.

Thanks,
Orquidea
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,942
Default Macro question

hi
Sheets("sheet2").range("A65000").end(xlup).offset( 1,0).pastespecial xlpasteall

regards
FSt1

"orquidea" wrote:

Hi:

I am having difficulty writing a procedure which copy one row from sheet 1
in the first row available in sheet 2.
Part of the loop procedure is below.

Do
If ActiveCell.Value = "TOR" Then
ActiveCell.EntireRow.Copy
Sheets("Sheet2"). (paste in column A in the first row available)

Could anyone help me please.

Thanks,
Orquidea

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,939
Default Macro question

I assume you are looking for all instances of TOR in a column on sheet 1 and
you want to copy those cells to the first available location on sheet 2. This
should do it all for you...

Public Sub CopyStuff()
Dim wksFrom As Worksheet
Dim wksTo As Worksheet
Dim rngFound As Range
Dim rngFoundAll As Range
Dim rngToSearch As Range
Dim strFirstAddress As String

Set wksFrom = Sheets("Sheet1") 'change sheet from
Set wksTo = Sheets("Sheet2") 'change destination sheet
Set rngToSearch = wksFrom.Columns("A") 'Change column to search
Set rngFound = rngToSearch.Find(What:="TOR", _
LookAt:=xlWhole, _
LookIn:=xlValues, _
MatchCase:=True)
If rngFound Is Nothing Then
MsgBox "TOR was not found"
Else
strFirstAddress = rngFound.Address
Set rngFoundAll = rngFound
Do
Set rngFoundAll = Union(rngFound, rngFoundAll)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = strFirstAddress
rngFoundAll.EntireRow.Copy _
wksTo.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
End If
End Sub
--
HTH...

Jim Thomlinson


"FSt1" wrote:

hi
Sheets("sheet2").range("A65000").end(xlup).offset( 1,0).pastespecial xlpasteall

regards
FSt1

"orquidea" wrote:

Hi:

I am having difficulty writing a procedure which copy one row from sheet 1
in the first row available in sheet 2.
Part of the loop procedure is below.

Do
If ActiveCell.Value = "TOR" Then
ActiveCell.EntireRow.Copy
Sheets("Sheet2"). (paste in column A in the first row available)

Could anyone help me please.

Thanks,
Orquidea

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 132
Default Macro question

Thanks for your help

"FSt1" wrote:

hi
Sheets("sheet2").range("A65000").end(xlup).offset( 1,0).pastespecial xlpasteall

regards
FSt1

"orquidea" wrote:

Hi:

I am having difficulty writing a procedure which copy one row from sheet 1
in the first row available in sheet 2.
Part of the loop procedure is below.

Do
If ActiveCell.Value = "TOR" Then
ActiveCell.EntireRow.Copy
Sheets("Sheet2"). (paste in column A in the first row available)

Could anyone help me please.

Thanks,
Orquidea

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 132
Default Macro question

Thanks for reading my mind. The macro below is exactly what I needed.

"Jim Thomlinson" wrote:

I assume you are looking for all instances of TOR in a column on sheet 1 and
you want to copy those cells to the first available location on sheet 2. This
should do it all for you...

Public Sub CopyStuff()
Dim wksFrom As Worksheet
Dim wksTo As Worksheet
Dim rngFound As Range
Dim rngFoundAll As Range
Dim rngToSearch As Range
Dim strFirstAddress As String

Set wksFrom = Sheets("Sheet1") 'change sheet from
Set wksTo = Sheets("Sheet2") 'change destination sheet
Set rngToSearch = wksFrom.Columns("A") 'Change column to search
Set rngFound = rngToSearch.Find(What:="TOR", _
LookAt:=xlWhole, _
LookIn:=xlValues, _
MatchCase:=True)
If rngFound Is Nothing Then
MsgBox "TOR was not found"
Else
strFirstAddress = rngFound.Address
Set rngFoundAll = rngFound
Do
Set rngFoundAll = Union(rngFound, rngFoundAll)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = strFirstAddress
rngFoundAll.EntireRow.Copy _
wksTo.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
End If
End Sub
--
HTH...

Jim Thomlinson


"FSt1" wrote:

hi
Sheets("sheet2").range("A65000").end(xlup).offset( 1,0).pastespecial xlpasteall

regards
FSt1

"orquidea" wrote:

Hi:

I am having difficulty writing a procedure which copy one row from sheet 1
in the first row available in sheet 2.
Part of the loop procedure is below.

Do
If ActiveCell.Value = "TOR" Then
ActiveCell.EntireRow.Copy
Sheets("Sheet2"). (paste in column A in the first row available)

Could anyone help me please.

Thanks,
Orquidea

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
Macro Question Vick Excel Discussion (Misc queries) 1 November 27th 07 02:58 PM
Macro Question Carl Excel Worksheet Functions 1 August 24th 06 09:03 PM
Macro Question Diana Excel Discussion (Misc queries) 1 July 15th 06 12:28 AM
Macro Question carl Excel Worksheet Functions 0 June 7th 06 06:14 PM
Macro Question sony654 Excel Worksheet Functions 3 February 27th 06 09:55 PM


All times are GMT +1. The time now is 02:15 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"