What is wrong with my VB codes? Please help!

plainme

Board Regular
Joined
Mar 23, 2010
Messages
60
I want to copy and paste the Range of A4:H2004 in the tab of DataA to the Range of (A1:H2001) in the tab of DataB. Please see my code below.

Thank you!

Sub CopyPasteNewDataToNewTab()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
Dim A As Range<o:p></o:p>
<o:p> </o:p>
Workbooks("2011Data.xls").Activate<o:p></o:p>
A = Workbooks("2011Data.xls").Sheets("DataA").Range("A4:H2004").Value<o:p></o:p>
Workbooks("2011Data").Sheets("DataB").Range("A1:H2001").Value = A<o:p></o:p>
<o:p> </o:p>
End Sub
 

Some videos you may like

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Tuelor

Board Regular
Joined
Mar 19, 2011
Messages
101
Just have one range.value equal to the other, and ignore A.

D
 

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
You can do it in one line:

Sheets("DataA").Range("A4:H2004").Copy Sheets("DataB").Range("A1")

HTH,
 

plainme

Board Regular
Joined
Mar 23, 2010
Messages
60
You can do it in one line:

Sheets("DataA").Range("A4:H2004").Copy Sheets("DataB").Range("A1")

HTH,

Thanks! It works.

Do you have any idea why the sorting code below does not work?


Range("A1:2001").Select
Selection.Sort Key1:=Range("K2"), Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
 

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
19,267
Office Version
  1. 2013
Platform
  1. Windows

ADVERTISEMENT

Your missing a letter here.
and remove Select.Selection text

Rich (BB code):
Range("A1:A2001").Sort Key1:=Range("K2"), Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
 

plainme

Board Regular
Joined
Mar 23, 2010
Messages
60
Your missing a letter here.
and remove Select.Selection text

Rich (BB code):
Range("A1:A2001").Sort Key1:=Range("K2"), Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

Thanks. Still doesn't work.
 

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
19,267
Office Version
  1. 2013
Platform
  1. Windows
Maybe you should post the entire sub.
Are you getting an error or nothing happening at all ?
Have you tried stepping through the code line by line using F8 ?
Usually the sort key is the first cell in the selected range ??, why "K2" ??
 

Watch MrExcel Video

Forum statistics

Threads
1,109,227
Messages
5,527,539
Members
409,769
Latest member
Hudz

This Week's Hot Topics

Top