PC Review


Reply
Thread Tools Rate Thread

Copy dynamic range

 
 
Sandy
Guest
Posts: n/a
 
      18th Apr 2008
Hello
I have some code that was given to me and I have modified. I am trying to
modify again and I am having trouble. I am opening files manipulating data
and then copying to another workbook where inthe macro lies. All of the
manipulation works but when I try to copy I am getting nothing. I am
thinking that it may be in my use of "lastrow" but I am not sure how to fix
it. This is the excerpt of the code...

lastrow = Cells(Cells.Rows.Count, "a").End(xlUp).Row
Set sourceRange = mybook.Worksheets(1).Range("A2:H" & lastrow)
Call SortArray(MyFiles)

SourceRcount = sourceRange.Rows.Count
Set destrange = basebook.Worksheets(1).Range("A" & rnum)

SourceRcount = sourceRange.Rows.Count
Set destrange = basebook.Worksheets(1).Range("A" & rnum)

With sourceRange
Set destrange = basebook.Worksheets(1).Cells(rnum,
"A"). _
Resize(.Rows.Count, .Columns.Count)
End With
destrange.Value = sourceRange.Value




Sub SortArray(myArr As Variant)
Dim iCtr As Long
Dim jCtr As Long
Dim Temp As Variant
For iCtr = LBound(myArr) To UBound(myArr) - 1
For jCtr = iCtr + 1 To UBound(myArr)
If LCase(Right(myArr(iCtr), 10)) _
> LCase(Right(myArr(jCtr), 10)) Then

Temp = myArr(iCtr)
myArr(iCtr) = myArr(jCtr)
myArr(jCtr) = Temp
End If
Next jCtr
Next iCtr
End Sub


TIA
Sandy
 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      18th Apr 2008
from
lastrow = Cells(Cells.Rows.Count, "a").End(xlUp).Row
to

lastrow = mybook.Worksheets(1).Cells(Rows.Count, "a").End(xlUp).Row



"Sandy" wrote:

> Hello
> I have some code that was given to me and I have modified. I am trying to
> modify again and I am having trouble. I am opening files manipulating data
> and then copying to another workbook where inthe macro lies. All of the
> manipulation works but when I try to copy I am getting nothing. I am
> thinking that it may be in my use of "lastrow" but I am not sure how to fix
> it. This is the excerpt of the code...
>
> lastrow = Cells(Cells.Rows.Count, "a").End(xlUp).Row
> Set sourceRange = mybook.Worksheets(1).Range("A2:H" & lastrow)
> Call SortArray(MyFiles)
>
> SourceRcount = sourceRange.Rows.Count
> Set destrange = basebook.Worksheets(1).Range("A" & rnum)
>
> SourceRcount = sourceRange.Rows.Count
> Set destrange = basebook.Worksheets(1).Range("A" & rnum)
>
> With sourceRange
> Set destrange = basebook.Worksheets(1).Cells(rnum,
> "A"). _
> Resize(.Rows.Count, .Columns.Count)
> End With
> destrange.Value = sourceRange.Value
>
>
>
>
> Sub SortArray(myArr As Variant)
> Dim iCtr As Long
> Dim jCtr As Long
> Dim Temp As Variant
> For iCtr = LBound(myArr) To UBound(myArr) - 1
> For jCtr = iCtr + 1 To UBound(myArr)
> If LCase(Right(myArr(iCtr), 10)) _
> > LCase(Right(myArr(jCtr), 10)) Then

> Temp = myArr(iCtr)
> myArr(iCtr) = myArr(jCtr)
> myArr(jCtr) = Temp
> End If
> Next jCtr
> Next iCtr
> End Sub
>
>
> TIA
> Sandy

 
Reply With Quote
 
Sandy
Guest
Posts: n/a
 
      18th Apr 2008
Thanks for the response.
I stll get nothing after your suggested change.
S

"Joel" wrote:

> from
> lastrow = Cells(Cells.Rows.Count, "a").End(xlUp).Row
> to
>
> lastrow = mybook.Worksheets(1).Cells(Rows.Count, "a").End(xlUp).Row
>
>
>
> "Sandy" wrote:
>
> > Hello
> > I have some code that was given to me and I have modified. I am trying to
> > modify again and I am having trouble. I am opening files manipulating data
> > and then copying to another workbook where inthe macro lies. All of the
> > manipulation works but when I try to copy I am getting nothing. I am
> > thinking that it may be in my use of "lastrow" but I am not sure how to fix
> > it. This is the excerpt of the code...
> >
> > lastrow = Cells(Cells.Rows.Count, "a").End(xlUp).Row
> > Set sourceRange = mybook.Worksheets(1).Range("A2:H" & lastrow)
> > Call SortArray(MyFiles)
> >
> > SourceRcount = sourceRange.Rows.Count
> > Set destrange = basebook.Worksheets(1).Range("A" & rnum)
> >
> > SourceRcount = sourceRange.Rows.Count
> > Set destrange = basebook.Worksheets(1).Range("A" & rnum)
> >
> > With sourceRange
> > Set destrange = basebook.Worksheets(1).Cells(rnum,
> > "A"). _
> > Resize(.Rows.Count, .Columns.Count)
> > End With
> > destrange.Value = sourceRange.Value
> >
> >
> >
> >
> > Sub SortArray(myArr As Variant)
> > Dim iCtr As Long
> > Dim jCtr As Long
> > Dim Temp As Variant
> > For iCtr = LBound(myArr) To UBound(myArr) - 1
> > For jCtr = iCtr + 1 To UBound(myArr)
> > If LCase(Right(myArr(iCtr), 10)) _
> > > LCase(Right(myArr(jCtr), 10)) Then

> > Temp = myArr(iCtr)
> > myArr(iCtr) = myArr(jCtr)
> > myArr(jCtr) = Temp
> > End If
> > Next jCtr
> > Next iCtr
> > End Sub
> >
> >
> > TIA
> > Sandy

 
Reply With Quote
 
Sandy
Guest
Posts: n/a
 
      18th Apr 2008
Nevermind its working THANKS!

"Joel" wrote:

> from
> lastrow = Cells(Cells.Rows.Count, "a").End(xlUp).Row
> to
>
> lastrow = mybook.Worksheets(1).Cells(Rows.Count, "a").End(xlUp).Row
>
>
>
> "Sandy" wrote:
>
> > Hello
> > I have some code that was given to me and I have modified. I am trying to
> > modify again and I am having trouble. I am opening files manipulating data
> > and then copying to another workbook where inthe macro lies. All of the
> > manipulation works but when I try to copy I am getting nothing. I am
> > thinking that it may be in my use of "lastrow" but I am not sure how to fix
> > it. This is the excerpt of the code...
> >
> > lastrow = Cells(Cells.Rows.Count, "a").End(xlUp).Row
> > Set sourceRange = mybook.Worksheets(1).Range("A2:H" & lastrow)
> > Call SortArray(MyFiles)
> >
> > SourceRcount = sourceRange.Rows.Count
> > Set destrange = basebook.Worksheets(1).Range("A" & rnum)
> >
> > SourceRcount = sourceRange.Rows.Count
> > Set destrange = basebook.Worksheets(1).Range("A" & rnum)
> >
> > With sourceRange
> > Set destrange = basebook.Worksheets(1).Cells(rnum,
> > "A"). _
> > Resize(.Rows.Count, .Columns.Count)
> > End With
> > destrange.Value = sourceRange.Value
> >
> >
> >
> >
> > Sub SortArray(myArr As Variant)
> > Dim iCtr As Long
> > Dim jCtr As Long
> > Dim Temp As Variant
> > For iCtr = LBound(myArr) To UBound(myArr) - 1
> > For jCtr = iCtr + 1 To UBound(myArr)
> > If LCase(Right(myArr(iCtr), 10)) _
> > > LCase(Right(myArr(jCtr), 10)) Then

> > Temp = myArr(iCtr)
> > myArr(iCtr) = myArr(jCtr)
> > myArr(jCtr) = Temp
> > End If
> > Next jCtr
> > Next iCtr
> > End Sub
> >
> >
> > TIA
> > Sandy

 
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
Copy Dynamic Range problem Len Microsoft Excel Programming 2 10th Jan 2010 03:08 PM
Dynamic copy range LiAD Microsoft Excel Programming 12 2nd Sep 2009 09:36 AM
Macro to copy a certain a cell to a dynamic range Frank Situmorang Microsoft Excel Programming 5 14th Mar 2008 04:26 AM
Copy via code from a dynamic range using offeset Greg Microsoft Excel Programming 5 8th Aug 2005 05:13 PM
Dynamic range copy. sungen99 Microsoft Excel Programming 1 10th Jun 2005 04:44 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:18 AM.