ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Move rows to a new file (https://www.excelbanter.com/excel-programming/355718-move-rows-new-file.html)

[email protected]

Move rows to a new file
 
I'm running into some difficulties breaking up an excel file into a
number of different excel files. Basically, I have a file with a large
number of "sections"- the number of sections can vary from file to
file, and the number of rows under each section can vary from file to
file. I have it set up so that everytime there is a new chunk of data,
the word "Layer" appears in column B. I was hoping that I could start
from the bottom and work my way up, taking the last row, then finding
the beginning of the section by location the last "Layer" in column B.
Here's an example of what I'm talking about:

A B C
data Layer data
data data data
data Layer data
data data data
data data data
data data data
data Layer data
data Layer data

I had started to piece something together to identify the section, then
I was going to select the range and move it to a new file. Here's what
I have so far:

Sub SectionSelection()

Dim lastrow As Integer
Dim firstrow As Integer

lastrow = Range("B" & Rows.Count).End(xlUp).Row

Application.ScreenUpdating = False
Range("B65536").End(xlUp).Select
While ActiveCell.Row 5
If ActiveCell.Value = "Layer" Then
firstrow = ActiveCell.Row
End If
ActiveCell.Offset(-1, 0).Select
Wend


End Sub

This doesn't work because even though it finds the "firstrow", it
continues through the loop so that I can't do anything with my
variable. Ideally what I would like to do is identify the last row,
then the first row of the section, move it to a new file and save it,
then continue through the next section of the file.

Any ideas would be appreciated!

Thanks,
Marny



All times are GMT +1. The time now is 04:20 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com