简体   繁体   中英

Excel Macro - Copying data from one sheet to the next

Hoping someone can help me here..... im new so go easy on me! ;-)

Ive got 2 sheets - 1 "LINK" and 2 "RAW Data"

Now what I want the macro to do is copy data from the "LINK" sheet and put it into the correct columns in the "raw data sheet" - however when the macro is complete, it appears to be putting data in the wrong column (Should start in Column B - Raw Data) - but is replacing data in column A.....Is that because the data Im copying from "LINK" starts in column A?

Is this something to do with it referencing the active window? Is there a way to hard code it so it always checks from rows 4-750 (as data will fluctuate between that many rows).

Please advise

I'm simply turning the macro on and recording a copy, paste special values & formats - here is a clip of beginning of the code it has created.

Range("A5:C5").Select 
Range(Selection, Selection.End(xlDown)).Select 
Selection.Copy 
Sheets("RAW Data").Select 
Range("B4").Select 
Selection.PasteSpecial _ 
    Paste:=xlPasteValuesAndNumberFormats, _
    Operation:= _ xlNone, _
    SkipBlanks:=False, _ 
    Transpose:=False 
Range("E4").Select 
Sheets("LINK").Select
Range("E5:F5").Select

I may have misunderstood, but I'm not sure that there is any need for a macro at all.

If all you are trying to do is 'copy' one sheet column into another sheet column, then it is much easier to do so without a macro. For the example columns you've given, simply type ='LINK'!A1 into cell B1 in your "raw data sheet" sheet. You can then drag this vertically/horizontally to the extents that you need copying from the other sheet.

If you're just doing this to learn some VB however, the function you are looking for is called Range. A very good resource for learning some simple VB is http://www.homeandlearn.org/

Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM