Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default Moving data between worksheets in VBA

Hi all,

I'm trying to evaluate a list in a column. When I reach a row that contains
a "=", I'd like to create a new worksheet and cut and paste all the entries
following into that new sheet.

For example:

Sheet 1:
Monkeys
Cinnamon
Car Keys
=
Root Beer

Sheet 2:
Root Beer

Any thoughts on the best way to approach the code?

Thanks in advance, this forum is amazing!

Mike
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Moving data between worksheets in VBA

Hi Mike,
Try:
'-------------------------------------
Sub test()
Dim WshS As Worksheet, WshD As Worksheet 'Source, Destination sheets
Dim Rg, RgS As Range, RgD As Range 'a range, source, dest. ranges

Set WshS = Worksheets("sheet1")
Set RgS = WshS.Range("A:A")

Set Rg = RgS.Find(what:="=", after:=RgS.Cells(RgS.Cells.Count),
LookIn:=xlValues, lookat:=xlWhole)
If Rg Is Nothing Then 'doesn't exist
MsgBox "Cannot find =."
Else
'add a sheet
Set WshD = Worksheets.Add
Set Rg = Range(Rg.Offset(1, 0), Rg.Parent.Cells(65536,
Rg.Column).End(xlUp))
Application.CutCopyMode = False
Rg.Copy WshD.Range("A1")
End If
End Sub
'-------------------------------------------

Regards,
Sebastien


"Mike" wrote:

Hi all,

I'm trying to evaluate a list in a column. When I reach a row that contains
a "=", I'd like to create a new worksheet and cut and paste all the entries
following into that new sheet.

For example:

Sheet 1:
Monkeys
Cinnamon
Car Keys
=
Root Beer

Sheet 2:
Root Beer

Any thoughts on the best way to approach the code?

Thanks in advance, this forum is amazing!

Mike

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Moving data between worksheets in VBA

Here is some code...
A little shorter than Sebastiens but not a remarkably different...

Private Const SEARCHSTRING As String = "="

Public Sub TransferOnEqual()
Dim rngStart As Range
Dim rngFound As Range
Dim rngToSearch As Range

Set rngToSearch = Sheet1.Range("A1").EntireColumn
Set rngFound = rngToSearch.Find(SEARCHSTRING, , , xlWhole)
Set rngStart = rngFound

If rngFound Is Nothing Then
MsgBox "Nothin Found"
Else
Do
rngFound.Offset(1, 0).EntireRow.Copy
Sheets.Add
ActiveSheet.Paste
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngStart.Address = rngFound.Address
End If

End Sub

"Mike" wrote:

Hi all,

I'm trying to evaluate a list in a column. When I reach a row that contains
a "=", I'd like to create a new worksheet and cut and paste all the entries
following into that new sheet.

For example:

Sheet 1:
Monkeys
Cinnamon
Car Keys
=
Root Beer

Sheet 2:
Root Beer

Any thoughts on the best way to approach the code?

Thanks in advance, this forum is amazing!

Mike

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
moving filtered data between worksheets automatically dweezy Excel Worksheet Functions 3 October 4th 06 03:10 PM
Moving Table Data to other worksheets. Chuck Excel Worksheet Functions 4 March 8th 06 08:45 PM
Moving data between worksheets ... Ian Edmont Excel Discussion (Misc queries) 5 January 19th 06 09:32 AM
Moving data between worksheets ... Ian Edmont Excel Worksheet Functions 4 January 19th 06 09:32 AM
Moving data between worksheets Joe Excel Worksheet Functions 0 January 27th 05 08:38 PM


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