Solved

Cut , Paste and Delete data

Posted on 2011-03-13
13
234 Views
Last Modified: 2012-05-11
Hi Experts,

I would like to request Experts help create a macro to cut and paste data from Sheet3 (row2 to row 500)  to Sheet 2. After the data being processed using “Sub CopyData()”, the output at “Matched” sheet need to be copied over at “Completed” sheet and delete Sheet2 data automatically. Need to loop this process until the Hope Experts will help me to create this feature. Attached the workbook for Experts perusal.



CopyDataTest.xls
0
Comment
Question by:Cartillo
  • 7
  • 6
13 Comments
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35127273
>>>I would like to request Experts help create a macro to cut and paste data from Sheet3 (row2 to row 500)  to Sheet 2.

Try this. Paste this in a module.

Sub CopyDataS3S2()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim ws1LastRow As Long, ws2LastRow As Long
    Dim i As Long
    
    Set ws1 = Sheets("Sheet3")
    Set ws2 = Sheets("Sheet2")
    
    ws1LastRow = ws1.Range("A" & Rows.Count).End(xlUp).Row
    ws2LastRow = ws2.Range("A" & Rows.Count).End(xlUp).Row + 1
    
    ws1.Rows("2:" & ws1LastRow).Cut _
    ws2.Rows(ws2LastRow)
End Sub

Open in new window


Looking at the rest of your requirements.

Sid
0
 

Author Comment

by:Cartillo
ID: 35127363
Hi Sid,

Can we fixed the macro only cut and paste 500rows each time I run the sub. This is because I’m having more than 60,000 (millions data) rows. I need to run the ““Sub CopyData()” first before rerun the “Sub CopyDataS3S2()” Hope this is possible.
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35128368
Sorry had stepped out.

Which macro do you want to fix? Sub CopyData()?

Sid
0
 

Author Comment

by:Cartillo
ID: 35129219
Hi Sid,

Sorry for the confusion. Need to refine "Sub CopyDataS3S2" to allow Cut and Paste data from row 1 to row 500 only when each time I run the code.
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35130197
>>> Need to refine "Sub CopyDataS3S2" to allow Cut and Paste data from row 1 to row 500 only when each time I run the code.

Ok in that case paste the code that I gave in a module and then in your Sub CopyData() just add this one line at the end before End Sub

Sub CopyData()
    Dim strTmp As String
    Dim strTmp1 As String
    'Build the data dictionary
    Dim oDicTmp As Object
    Set oDicTmp = CreateObject("Scripting.Dictionary")

    '~~> Rest of the code remains as it is
    
    '~~> Add this line
    CopyDataS3S2
End Sub

Sub CopyDataS3S2()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim ws1LastRow As Long, ws2LastRow As Long
    Dim i As Long
    
    Set ws1 = Sheets("Sheet3")
    Set ws2 = Sheets("Sheet2")
    
    ws1LastRow = ws1.Range("A" & Rows.Count).End(xlUp).Row
    ws2LastRow = ws2.Range("A" & Rows.Count).End(xlUp).Row + 1
    
    ws1.Rows("2:" & ws1LastRow).Cut _
    ws2.Rows(ws2LastRow)
End Sub

Open in new window


Hope I have understood you correctly.

Sid
0
 

Author Comment

by:Cartillo
ID: 35130693
Hi Sid,

I think I just don't know how to put it in a simple words for you to understand. Sorry for that. What I need is to limit the cut and paste function up to 500 lines only from sheet 3 to sheet 2.  
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35130705
Oh Ok. 1st 500?

Sid
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35130717
If yes, then try this

Sub CopyDataS3S2()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim ws1LastRow As Long, ws2LastRow As Long
    Dim i As Long
    
    Set ws1 = Sheets("Sheet3")
    Set ws2 = Sheets("Sheet2")
    
    ws1LastRow = ws1.Range("A" & Rows.Count).End(xlUp).Row
    ws2LastRow = ws2.Range("A" & Rows.Count).End(xlUp).Row + 1
    
    ws1.Rows("2:501").Cut ws2.Rows(ws2LastRow)
End Sub

Open in new window


Sid
0
 

Author Comment

by:Cartillo
ID: 35130721
Hi,

Yes, you're right.
0
 

Author Comment

by:Cartillo
ID: 35130827
Hi Sid,

How to set Sheet 3 data is "Shift:=xlUp" after cut the data (prevent any empty rows). This is to allow me to copy the same data row again.
0
 

Author Comment

by:Cartillo
ID: 35134066
Hi Sid,

Please let me know if this is not giving you better picture.
0
 
LVL 30

Accepted Solution

by:
SiddharthRout earned 500 total points
ID: 35134473
Try this.

Sub CopyDataS3S2()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim ws1LastRow As Long, ws2LastRow As Long
    Dim i As Long
    
    Set ws1 = Sheets("Sheet3")
    Set ws2 = Sheets("Sheet2")
    
    ws1LastRow = ws1.Range("A" & Rows.Count).End(xlUp).Row
    ws2LastRow = ws2.Range("A" & Rows.Count).End(xlUp).Row + 1
    
    ws1.Rows("2:501").Cut ws2.Rows(ws2LastRow)
    ws1.Cells.SpecialCells(xlCellTypeBlanks).Delete shift:=xlUp
End Sub

Open in new window


Sid
0
 

Author Closing Comment

by:Cartillo
ID: 35146616
Thanks a lot Sid.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now