• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Simple cut paste VBA

Hi Guys,

i need simple cut paste code that can cut an entire row in sheet1 and paste in sheet2. If you can tell me the code it will be a great help

PS: Please see below the method

Sheet1

A1 B1 C1 D1 E1 F1 G1

I need a code that can paste the value in sheet2

A1 C1 E1
B2 D2 F2


like zigzag


Thanks in anticipation

Manish
 
manish

In Sheet2!A1 put =Sheet1!A1
In Sheet2!B1 put =NOT(ISODD(ROW()+COLUMN()))*OFFSET(Sheet1!$A$1,,COUNTIF($A$1:A$2,">0"))

Copy down and across to G2
Select A1:G2
Ctrl 1
Number, Custom
Apply the format 0;0;;

see attached file:
 

Attachments

  • Book1.xlsx
    8.9 KB · Views: 1
Dear Hui and Narayan Sir,

Thanks for your reply.

Please see the attached file


Thanks
Manish
 

Attachments

  • Sample file.xlsm
    10.3 KB · Views: 5
Code:
Sub master()
Call Insert_Blank_Rows
Call copypaste
Call SavetoWB

End Sub
Sub Insert_Blank_Rows()
     'Select last row in worksheet.
    Selection.End(xlDown).Select
    Do Until ActiveCell.Row = 1
         'Insert blank row.
        ActiveCell.EntireRow.Insert shift:=xlDown
         'Move up one row.
        ActiveCell.Offset(-1, 0).Select
    Loop
End Sub

Sub SavetoWB()  'Excel VBA to export data
Const sPath = "D:\"
Dim ar As Variant
Dim i As Integer
Dim owb As Workbook

Range("A3", Range("A" & Rows.Count).End(xlUp)).AdvancedFilter xlFilterCopy, , [T1], True
ar = Range("T2", Range("T2").End(xlDown))
'Loop through all unique instances of the Results from the Advanced Filter.
   For i = 1 To UBound(ar)
        Range("A3", Range("A" & Rows.Count).End(xlUp)).AutoFilter 1, ar(i, 1)
        Range("A3", Range("N" & Rows.Count).End(xlUp)).Copy 'Where Data is from Col A - N
       Set owb = Workbooks.Add
        owb.Sheets(1).[A1].PasteSpecial xlPasteValues
        owb.SaveAs sPath & [A2]
        owb.Close False 'Close no save
   Next i
[a3].AutoFilter
Columns(20).EntireColumn.Clear
End Sub

Sub copypaste()
Range("B1").Select
Selection.Cut
Range("B2").Select
ActiveSheet.Paste
Range("D1").Select
Selection.Cut
Range("D2").Select
ActiveSheet.Paste
Range("F1").Select
Selection.Cut
Range("F2").Select
ActiveSheet.Paste
Range("H1").Select
Selection.Cut
Range("H2").Select
ActiveSheet.Paste
End Sub

[\code]

This are the codes you can see it by Alt+F11


and finally this is for changing to csv
[code]

Sub SaveToCSVs()


Dim fDir AsString

Dim wB As Workbook

Dim wS As Worksheet

Dim fPath AsString

Dim sPath AsString


fPath ="C:\temp\pydev\"

sPath ="C:\temp\"

fDir = Dir(fPath)

DoWhile(fDir <>"")

If Right(fDir,4)=".xls"Or Right(fDir,5)=".xlsx"Then

OnErrorResumeNext

Set wB = Workbooks.Open(fPath & fDir)

ForEach wS In wB.Sheets

wS.SaveAs sPath & wS.Name, xlCSV


Next wS

wB.Close False

Set wB =Nothing

EndIf

fDir = Dir

OnErrorGoTo0

Loop


EndSub
 
If there are multiple entries for each Manish as below
upload_2014-11-27_20-25-2.png

I assume they all go into the same file in the same format, as new rows?

You said . eliminated
Do you mean comma delimitered or dot delimitered ?
 
If there are Multiple values of Field 1 "Manish 11"
is the following correct ?

upload_2014-11-27_22-29-7.png
 
Can you see how this goes for you?
It will put the CSV files in the same directory as the workbook
 

Attachments

  • Sample file.xlsm
    27.8 KB · Views: 1
Hui Sir,

Yes this is exactly what i want. Save to CSV format is awesome, thanks for this but not in a single workbook with lots of spreadsheets like (Shee1, sheet 2.......).

i need to create separate workbook for each entry.

Thanks
Manish
 
OMG!!! Thanks a lot hui sir you made my day

Thank you very very much.. you are such a genius. i did not see all the workbooks in my desktop :p

Thank you
Manish
 
Manish

I'm sorry I didn't re-use any of your code
It is so much quicker to start from scratch, but you can go through my code as you require and investigate what i have done
 
Back
Top