LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 661
Default Macro to find a range that varies.

Hi,
I want to write a macro that finds a range between two "find" terms, so I
can cut it from a sheet and post into another sheet.

So, I first want to find "Reconciliations" in column D. Then find "Account
Balance"in column D. I then want to cut the rows between these two rows and
paste into another sheet. I will then run the macro again to find the next
occurences. So, the first time "Reconciliations" might be in row 50 and
"Account Balance" in row 60, so I cut rows 50 to 60. Next time
"Reconciliations" is in row 100 and "Account Balance" in row 145, so I cut
rows 100 to 145.

Below is the macro I want to modify, so any help would be greatly appreciated.

Thanks for looking

Paul

Sub Pastedetails()


'
' Cutpaste Macro
' Macro recorded 22/11/2005 by IT Services
'
' Keyboard Shortcut: Ctrl+x
Dim rngFound As Range
Dim sStart As String
Dim sDestRange As String

Sheets("Posting").Activate
sStart = "D1"
sDestRange = "D1"

Range(sStart).Select

Set rngFound = Cells.Find(What:="Reconciliations", After:=ActiveCell,
LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByColumns,
SearchDirection:=xlNext)

I think this is where I would have to modify the macro to find "Account
Balance" and set the range to be cut.


Do While Not rngFound Is Nothing

If Not rngFound Is Nothing Then
Range(rngFound.Offset(0, 0).Address, rngFound.Offset(13,
0).Address).EntireRow.Cut

Sheets("Summary").Activate
ActiveCell.SpecialCells (xlCellTypeLastCell)


ActiveSheet.Paste

sDestRange = Range(sDestRange).End(xlDown).Offset(1, 0).Address

Cells.Select
Cells.EntireColumn.AutoFit

Sheet1.Activate
End If

Range(rngFound.Offset(1, 0).Address).Activate

Set rngFound = Cells.FindNext(After:=ActiveCell)


Windows("Control1.xls").Activate
ActiveCell.SpecialCells(xlCellTypeLastCell).Offset (1, -5).Select


Loop
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
Can a range be copied if it varies in size? TheMilkGuy Excel Discussion (Misc queries) 4 August 12th 09 10:05 PM
Setting a range that varies Stephen English Excel Programming 2 April 6th 09 08:43 PM
Sum of a range that varies Sebastien Excel Discussion (Misc queries) 1 February 19th 08 04:19 PM
Find character when the length varies Rookie_User Excel Discussion (Misc queries) 3 April 12th 06 07:17 PM
Insert SUM Formula using VBA (Range Varies) William Horton Excel Programming 6 August 8th 05 03:18 PM


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