PC Review


Reply
Thread Tools Rate Thread

Copy cells that vary in range

 
 
=?Utf-8?B?QkNMaXZlbGw=?=
Guest
Posts: n/a
 
      8th Jun 2007
Hi everyone!

I need some assistence to come up with come code that will copy a range of
cells from a single column. The text in the first cell and the last cell are
always the same. But sometimes there could be 5 cells inbetween and other
times there could be 100 cells inbetween. Below is what I ahve come up with
to so far to show where I am trying to go. Thank you for your help!!

startrow = Columns(2).Find("start example 1").Select
ActiveCell.Copy

******Need to also copy all cells inbetween here****

startrow = Columns(2).Find("end example 1").Select
ActiveCell.Copy
 
Reply With Quote
 
 
 
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      8th Jun 2007
Hi,

here's one way :


Sub test()
Dim rStart As Range
Dim rEnd As Range

Set rStart = Columns(2).Find("start example 1")

Set rEnd = Columns(2).Find("end example 1")

If Not rStart Is Nothing And Not rEnd Is Nothing Then
Range(rStart, rEnd).Copy
End If
End Sub



--
Hope that helps.

Vergel Adriano


"BCLivell" wrote:

> Hi everyone!
>
> I need some assistence to come up with come code that will copy a range of
> cells from a single column. The text in the first cell and the last cell are
> always the same. But sometimes there could be 5 cells inbetween and other
> times there could be 100 cells inbetween. Below is what I ahve come up with
> to so far to show where I am trying to go. Thank you for your help!!
>
> startrow = Columns(2).Find("start example 1").Select
> ActiveCell.Copy
>
> ******Need to also copy all cells inbetween here****
>
> startrow = Columns(2).Find("end example 1").Select
> ActiveCell.Copy

 
Reply With Quote
 
=?Utf-8?B?QkNMaXZlbGw=?=
Guest
Posts: n/a
 
      8th Jun 2007
Rock on!! thank you!!!!!

"Vergel Adriano" wrote:

> Hi,
>
> here's one way :
>
>
> Sub test()
> Dim rStart As Range
> Dim rEnd As Range
>
> Set rStart = Columns(2).Find("start example 1")
>
> Set rEnd = Columns(2).Find("end example 1")
>
> If Not rStart Is Nothing And Not rEnd Is Nothing Then
> Range(rStart, rEnd).Copy
> End If
> End Sub
>
>
>
> --
> Hope that helps.
>
> Vergel Adriano
>
>
> "BCLivell" wrote:
>
> > Hi everyone!
> >
> > I need some assistence to come up with come code that will copy a range of
> > cells from a single column. The text in the first cell and the last cell are
> > always the same. But sometimes there could be 5 cells inbetween and other
> > times there could be 100 cells inbetween. Below is what I ahve come up with
> > to so far to show where I am trying to go. Thank you for your help!!
> >
> > startrow = Columns(2).Find("start example 1").Select
> > ActiveCell.Copy
> >
> > ******Need to also copy all cells inbetween here****
> >
> > startrow = Columns(2).Find("end example 1").Select
> > ActiveCell.Copy

 
Reply With Quote
 
=?Utf-8?B?RlN0MQ==?=
Guest
Posts: n/a
 
      8th Jun 2007
hi
try something like this.....

Sub Macro1()
Dim f As Range
Dim l As Range
Set ws = Sheets("Sheet1")
With ws.Range("A1:A10000")
Set f = .Find("firstfind", LookIn:=xlValues)
Set l = .Find("lastfind", LookIn:=xlValues)
Range(f, l).Select
End With
End Sub
edit for your data

Regards
FSt1

"BCLivell" wrote:

> Hi everyone!
>
> I need some assistence to come up with come code that will copy a range of
> cells from a single column. The text in the first cell and the last cell are
> always the same. But sometimes there could be 5 cells inbetween and other
> times there could be 100 cells inbetween. Below is what I ahve come up with
> to so far to show where I am trying to go. Thank you for your help!!
>
> startrow = Columns(2).Find("start example 1").Select
> ActiveCell.Copy
>
> ******Need to also copy all cells inbetween here****
>
> startrow = Columns(2).Find("end example 1").Select
> ActiveCell.Copy

 
Reply With Quote
 
gordon.moar@googlemail.com
Guest
Posts: n/a
 
      8th Jun 2007
On 8 Jun, 13:58, BCLivell <BCLiv...@discussions.microsoft.com> wrote:
> I need some assistence to come up with come code that will copy a range of
> cells from a single column. The text in the first cell and the last cell are
> always the same. But sometimes there could be 5 cells inbetween and other
> times there could be 100 cells inbetween. Below is what I ahve come up with
> to so far to show where I am trying to go. Thank you for your help!!
>
> startrow = Columns(2).Find("start example 1").Select
> ActiveCell.Copy
>
> ******Need to also copy all cells inbetween here****
>
> startrow = Columns(2).Find("end example 1").Select
> ActiveCell.Copy


How will the range be populated? If it is by the insertion of rows
then you could name the range in the worksheet and just copy it,
regardless of how many rows are added.

Alternatively, do something like this:

Dim rngCopyRange As Range
Dim lngStartRow As Long
Dim lngEndRow As Long
lngStartRow = Columns(2).Find("start example 1").Row
lngEndRow = Columns(2).Find("end example 1").Row
Set rngCopyRange = Range("B" & lngStartRow & ":B" & lngEndRow)
rngCopyRange.Copy

--
juux


 
Reply With Quote
 
gordon.moar@googlemail.com
Guest
Posts: n/a
 
      8th Jun 2007
On 8 Jun, 15:00, gordon.m...@googlemail.com wrote:
> Dim rngCopyRange As Range
> Dim lngStartRow As Long
> Dim lngEndRow As Long
> lngStartRow = Columns(2).Find("start example 1").Row
> lngEndRow = Columns(2).Find("end example 1").Row
> Set rngCopyRange = Range("B" & lngStartRow & ":B" & lngEndRow)
> rngCopyRange.Copy
>
> --
> juux


...although Vergel's way is more elegant!

--
juux

 
Reply With Quote
 
=?Utf-8?B?QkNMaXZlbGw=?=
Guest
Posts: n/a
 
      8th Jun 2007
I forgot to ask about my next step which is pasting that range into another
worksheet starting at cell "a10" in the new worksheet. Thank you!

"Vergel Adriano" wrote:

> Hi,
>
> here's one way :
>
>
> Sub test()
> Dim rStart As Range
> Dim rEnd As Range
>
> Set rStart = Columns(2).Find("start example 1")
>
> Set rEnd = Columns(2).Find("end example 1")
>
> If Not rStart Is Nothing And Not rEnd Is Nothing Then
> Range(rStart, rEnd).Copy
> End If
> End Sub
>
>
>
> --
> Hope that helps.
>
> Vergel Adriano
>
>
> "BCLivell" wrote:
>
> > Hi everyone!
> >
> > I need some assistence to come up with come code that will copy a range of
> > cells from a single column. The text in the first cell and the last cell are
> > always the same. But sometimes there could be 5 cells inbetween and other
> > times there could be 100 cells inbetween. Below is what I ahve come up with
> > to so far to show where I am trying to go. Thank you for your help!!
> >
> > startrow = Columns(2).Find("start example 1").Select
> > ActiveCell.Copy
> >
> > ******Need to also copy all cells inbetween here****
> >
> > startrow = Columns(2).Find("end example 1").Select
> > ActiveCell.Copy

 
Reply With Quote
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      8th Jun 2007
try replacing this line

Range(rStart, rEnd).Copy

with this one

Range(rStart, rEnd).Copy ThisWorkbook.Worksheets.Add.Range("A10")


... if the destination is on a sheet that already exists, for example, a
sheet named "Sheet2", then, you can do it this way:

Range(rStart, rEnd).Copy ThisWorkbook.Worksheets("Sheet2").Range("A10")


--
Hope that helps.

Vergel Adriano


"BCLivell" wrote:

> I forgot to ask about my next step which is pasting that range into another
> worksheet starting at cell "a10" in the new worksheet. Thank you!
>
> "Vergel Adriano" wrote:
>
> > Hi,
> >
> > here's one way :
> >
> >
> > Sub test()
> > Dim rStart As Range
> > Dim rEnd As Range
> >
> > Set rStart = Columns(2).Find("start example 1")
> >
> > Set rEnd = Columns(2).Find("end example 1")
> >
> > If Not rStart Is Nothing And Not rEnd Is Nothing Then
> > Range(rStart, rEnd).Copy
> > End If
> > End Sub
> >
> >
> >
> > --
> > Hope that helps.
> >
> > Vergel Adriano
> >
> >
> > "BCLivell" wrote:
> >
> > > Hi everyone!
> > >
> > > I need some assistence to come up with come code that will copy a range of
> > > cells from a single column. The text in the first cell and the last cell are
> > > always the same. But sometimes there could be 5 cells inbetween and other
> > > times there could be 100 cells inbetween. Below is what I ahve come up with
> > > to so far to show where I am trying to go. Thank you for your help!!
> > >
> > > startrow = Columns(2).Find("start example 1").Select
> > > ActiveCell.Copy
> > >
> > > ******Need to also copy all cells inbetween here****
> > >
> > > startrow = Columns(2).Find("end example 1").Select
> > > ActiveCell.Copy

 
Reply With Quote
 
=?Utf-8?B?QkNMaXZlbGw=?=
Guest
Posts: n/a
 
      8th Jun 2007
Thank you!!

"Vergel Adriano" wrote:

> try replacing this line
>
> Range(rStart, rEnd).Copy
>
> with this one
>
> Range(rStart, rEnd).Copy ThisWorkbook.Worksheets.Add.Range("A10")
>
>
> .. if the destination is on a sheet that already exists, for example, a
> sheet named "Sheet2", then, you can do it this way:
>
> Range(rStart, rEnd).Copy ThisWorkbook.Worksheets("Sheet2").Range("A10")
>
>
> --
> Hope that helps.
>
> Vergel Adriano
>
>
> "BCLivell" wrote:
>
> > I forgot to ask about my next step which is pasting that range into another
> > worksheet starting at cell "a10" in the new worksheet. Thank you!
> >
> > "Vergel Adriano" wrote:
> >
> > > Hi,
> > >
> > > here's one way :
> > >
> > >
> > > Sub test()
> > > Dim rStart As Range
> > > Dim rEnd As Range
> > >
> > > Set rStart = Columns(2).Find("start example 1")
> > >
> > > Set rEnd = Columns(2).Find("end example 1")
> > >
> > > If Not rStart Is Nothing And Not rEnd Is Nothing Then
> > > Range(rStart, rEnd).Copy
> > > End If
> > > End Sub
> > >
> > >
> > >
> > > --
> > > Hope that helps.
> > >
> > > Vergel Adriano
> > >
> > >
> > > "BCLivell" wrote:
> > >
> > > > Hi everyone!
> > > >
> > > > I need some assistence to come up with come code that will copy a range of
> > > > cells from a single column. The text in the first cell and the last cell are
> > > > always the same. But sometimes there could be 5 cells inbetween and other
> > > > times there could be 100 cells inbetween. Below is what I ahve come up with
> > > > to so far to show where I am trying to go. Thank you for your help!!
> > > >
> > > > startrow = Columns(2).Find("start example 1").Select
> > > > ActiveCell.Copy
> > > >
> > > > ******Need to also copy all cells inbetween here****
> > > >
> > > > startrow = Columns(2).Find("end example 1").Select
> > > > ActiveCell.Copy

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Vary the Range in a Function =?Utf-8?B?Y2FybA==?= Microsoft Excel Worksheet Functions 3 17th May 2007 05:21 PM
Copy a range to cells above range petebud Microsoft Excel Programming 2 13th Jan 2006 08:58 PM
How to use macros to copy a range of cells which can exclude some cells which I didn't want to be copied? excelnovice Microsoft Excel Worksheet Functions 2 25th Sep 2005 12:38 AM
Copy cells into range of cells until cell change =?Utf-8?B?bWRlYW5kYQ==?= Microsoft Excel Worksheet Functions 1 22nd Apr 2005 08:41 PM
Copy a formula to a range of cells via VB6 using .Range(Cells(row,col), Cells(row,col)).Formula= statement Kevin Microsoft Excel Programming 7 5th Oct 2004 08:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:19 AM.