Welcome to the { mindfrost82.com } forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Go Back   { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > MS Office > Excel

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-06-2008, 06:11 AM
holt.david1@gmail.com
 
Posts: n/a
Excel macro for copying range to another worksheet

On a monthly basis, I would like to copy the completed range (varies
from month to month) of a database (Sheet1) to a master list (Sheet3).
Once the data has been copied I intend to manually delete the entries
of Sheet1 and start anew for the new month – for eventual transfer to
Sheet3.

The idea is to copy each month’s data at the bottom of the previous
months’ (Sheet3).
I followed Excel’s record macro command but the macro I ended up with
is not capable of placing the new data at the bottom of the existing
one; it simply keeps overwriting the previous entry.

Unfortunately, I don’t know enough VBA to tweak the code that the
record macro command produced. It appears that the first part,
selecting the non-blank cells and copying into Sheet3 works OK, but I
also would like to copy the new data at the bottom of previous
entries, and the code is not doing it.

Below is the code that I’m struggling with. Any help will be greatly
appreciated.

Dave


Sub DataTransfer()
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Range("A2:A22").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Sheets("Sheet3").Select
Range("A1").Select
Selection.End(xlDown).Select
Selection.End(xlUp).Select
Range("A2").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
End Sub
Reply With Quote
  #2 (permalink)  
Old 07-06-2008, 10:25 AM
Dave Mills
 
Posts: n/a
Re: Excel macro for copying range to another worksheet

On Sat, 5 Jul 2008 22:11:07 -0700 (PDT), holt.david1@gmail.com wrote:


>Below is the code that I’m struggling with. Any help will be greatly
>appreciated.


Use F8 (debug stepping) to step through the code one line at a time to see how
it works.
>
>Dave
>
>
>Sub DataTransfer()
> Range("A2").Select
> Range(Selection, Selection.End(xlDown)).Select

You could use the line below instead of the 2 above
Range("A2", Range("A2").End(xlDown)).Select


The next line changes the selection and thus makes the previous 2 lines
redundant and fixes the range to end at A22, probable incorrectly in the general
case. I suspect you should delete this line.
> Range("A2:A22").Select



> Range(Selection, Selection.End(xlToRight)).Select
> Selection.Copy
> Sheets("Sheet3").Select
> Range("A1").Select


This line takes you to the last line of data
> Selection.End(xlDown).Select


But this then moves to the top of the data
> Selection.End(xlUp).Select

and this selects cell A2
> Range("A2").Select


Delete the above 2 lines and use
Selection.Offset(1, 0).Select

> Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
>SkipBlanks:= _


> False, Transpose:=False
>End Sub


Thus the final code would be

Sub DataTransfer()
Range("A2", Range("A2").End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Sheets("Sheet3").Select
Range("A1").Select
Selection.End(xlDown).Select
Selection.Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
End Sub

--
Dave Mills
There are 10 type of people, those that understand binary and those that don't.
Reply With Quote
  #3 (permalink)  
Old 07-06-2008, 01:02 PM
Dave Peterson
 
Posts: n/a
Re: Excel macro for copying range to another worksheet

Another one:

Option Explicit
Sub DataTransfer2()

Dim RngToCopy As Range
Dim DestCell As Range
Dim LastRow As Long
Dim LastCol As Long

With Worksheets("Sheet1") 'or what you want
'based on what's used in column A
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

'based on what's used in row 1 (headers are nice!)
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column

Set RngToCopy = .Range("a2", .Cells(LastRow, LastCol))
End With

With Worksheets("Sheet3")
'based on column A
Set DestCell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
End With

RngToCopy.Copy
DestCell.PasteSpecial Paste:=xlValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

Application.CutCopyMode = False

End Sub


holt.david1@gmail.com wrote:
>
> On a monthly basis, I would like to copy the completed range (varies
> from month to month) of a database (Sheet1) to a master list (Sheet3).
> Once the data has been copied I intend to manually delete the entries
> of Sheet1 and start anew for the new month – for eventual transfer to
> Sheet3.
>
> The idea is to copy each month’s data at the bottom of the previous
> months’ (Sheet3).
> I followed Excel’s record macro command but the macro I ended up with
> is not capable of placing the new data at the bottom of the existing
> one; it simply keeps overwriting the previous entry.
>
> Unfortunately, I don’t know enough VBA to tweak the code that the
> record macro command produced. It appears that the first part,
> selecting the non-blank cells and copying into Sheet3 works OK, but I
> also would like to copy the new data at the bottom of previous
> entries, and the code is not doing it.
>
> Below is the code that I’m struggling with. Any help will be greatly
> appreciated.
>
> Dave
>
> Sub DataTransfer()
> Range("A2").Select
> Range(Selection, Selection.End(xlDown)).Select
> Range("A2:A22").Select
> Range(Selection, Selection.End(xlToRight)).Select
> Selection.Copy
> Sheets("Sheet3").Select
> Range("A1").Select
> Selection.End(xlDown).Select
> Selection.End(xlUp).Select
> Range("A2").Select
> Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
> SkipBlanks:= _
> False, Transpose:=False
> End Sub


--

Dave Peterson
Reply With Quote
  #4 (permalink)  
Old 07-06-2008, 01:29 PM
Don Guillett
 
Posts: n/a
Re: Excel macro for copying range to another worksheet

One way, withOUT selections, fired from the source sheet to copy values to
sheet 4

Sub copyvaluestoothersht()
lr = Cells(Rows.Count, 1).End(xlUp).row
With Sheets("sheet4")
dlr = .Cells(Rows.Count, 1).End(xlUp).row + 1
.Cells(2, "a").Resize(lr - 1).Value = _
Cells(2, "a").Resize(lr - 1).Value
'to delete the source column
'columns(1).delete
End With
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
dguillett1@austin.rr.com
<holt.david1@gmail.com> wrote in message
news:7fa28feb-e241-4b06-ae3c-6550e622b74d@m45g2000hsb.googlegroups.com...
On a monthly basis, I would like to copy the completed range (varies
from month to month) of a database (Sheet1) to a master list (Sheet3).
Once the data has been copied I intend to manually delete the entries
of Sheet1 and start anew for the new month – for eventual transfer to
Sheet3.

The idea is to copy each month’s data at the bottom of the previous
months’ (Sheet3).
I followed Excel’s record macro command but the macro I ended up with
is not capable of placing the new data at the bottom of the existing
one; it simply keeps overwriting the previous entry.

Unfortunately, I don’t know enough VBA to tweak the code that the
record macro command produced. It appears that the first part,
selecting the non-blank cells and copying into Sheet3 works OK, but I
also would like to copy the new data at the bottom of previous
entries, and the code is not doing it.

Below is the code that I’m struggling with. Any help will be greatly
appreciated.

Dave


Sub DataTransfer()
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Range("A2:A22").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Sheets("Sheet3").Select
Range("A1").Select
Selection.End(xlDown).Select
Selection.End(xlUp).Select
Range("A2").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
End Sub

Reply With Quote
  #5 (permalink)  
Old 07-09-2008, 07:07 AM
holt.david1@gmail.com
 
Posts: n/a
Re: Excel macro for copying range to another worksheet

On Jul 6, 5:02*am, Dave Peterson <peter...@verizonXSPAM.net> wrote:
> Another one:
>
> Option Explicit
> Sub DataTransfer2()
>
> * * Dim RngToCopy As Range
> * * Dim DestCell As Range
> * * Dim LastRow As Long
> * * Dim LastCol As Long
>
> * * With Worksheets("Sheet1") 'or what you want
> * * * * 'based on what's used in column A
> * * * * LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
>
> * * * * 'based on what's used in row 1 (headers are nice!)
> * * * * LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
>
> * * * * Set RngToCopy = .Range("a2", .Cells(LastRow, LastCol))
> * * End With
>
> * * With Worksheets("Sheet3")
> * * * * 'based on column A
> * * * * Set DestCell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
> * * End With
>
> * * RngToCopy.Copy
> * * DestCell.PasteSpecial Paste:=xlValues, Operation:=xlNone, _
> * * * * SkipBlanks:=False, Transpose:=False
>
> * * Application.CutCopyMode = False
>
> End Sub
>
>
>
> holt.dav...@gmail.com wrote:
>
> > On a monthly basis, I would like to copy the completed range (varies
> > from month to month) of a database (Sheet1) to a master list (Sheet3).
> > Once the data has been copied I intend to manually delete the entries
> > of Sheet1 and start anew for the new month – for eventual transfer to
> > Sheet3.

>
> > The idea is to copy each month’s data at the bottom of the previous
> > months’ (Sheet3).
> > I followed Excel’s record macro command but the macro I ended up with
> > is not capable of placing the new data at the bottom of the existing
> > one; it simply keeps overwriting the previous entry.

>
> > Unfortunately, I don’t know enough VBA to tweak the code that the
> > record macro command produced. It appears that the first part,
> > selecting the non-blank cells and copying into Sheet3 works OK, but I
> > also would like to copy the new data at the bottom of previous
> > entries, and the code is not doing it.

>
> > Below is the code that I’m struggling with. Any help will be greatly
> > appreciated.

>
> > Dave

>
> > Sub DataTransfer()
> > * * Range("A2").Select
> > * * Range(Selection, Selection.End(xlDown)).Select
> > * * Range("A2:A22").Select
> > * * Range(Selection, Selection.End(xlToRight)).Select
> > * * Selection.Copy
> > * * Sheets("Sheet3").Select
> > * * Range("A1").Select
> > * * Selection.End(xlDown).Select
> > * * Selection.End(xlUp).Select
> > * * Range("A2").Select
> > * * Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
> > SkipBlanks:= _
> > * * * * False, Transpose:=False
> > End Sub

>
> --
>
> Dave Peterson


Appreciate all the help. It worked!
Reply With Quote
Reply

  { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > MS Office > Excel


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

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



All times are GMT. The time now is 03:43 AM.


Powered by vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
© 1999-2008 mindfrost82.com v11.0


Sponsors:
Apply for Credit Card | Loan | Homeowner Loans | Currency Converter | Proxy



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114