Hello I got this almost working
I need to copy info imported from one worksheet to another, but need to paste to different columns than original.
Formula below works but if column C as example is empty then info from column A will paste to next available row, B will do the same in same row but C will paste at beginning of column instead of all in same row.
basically I want to copy paste the range but different columns. Hope I am clear.
And as a second question how can I do the same thing as below but instead of adding to the last row I would like to insert at beginning of worksheet and move everything else down
Thanks
this works if I want to paste in same columns as original but I want column A from worksheet2 in column A in transactions sheet. Column B from Sheet 2 to column C in transactions sheet
I need to copy info imported from one worksheet to another, but need to paste to different columns than original.
Formula below works but if column C as example is empty then info from column A will paste to next available row, B will do the same in same row but C will paste at beginning of column instead of all in same row.
basically I want to copy paste the range but different columns. Hope I am clear.
And as a second question how can I do the same thing as below but instead of adding to the last row I would like to insert at beginning of worksheet and move everything else down
Thanks
VBA Code:
Sub Macro3()
'use for bank account
Dim column_types() As Variant
ChDrive "E:\"
ChDir "E:\financialexcel\transactions\"
csv_path = Application.GetOpenFilename()
If csv_path = False Then
Exit Sub
End If
For i = 0 To 16384
ReDim Preserve column_types(i)
column_types(i) = 2
Next i
With ActiveWorkbook.Sheets(2).QueryTables.Add(Connection:="TEXT;" & csv_path, Destination:=Cells(Rows.Count, "A").End(xlUp).Offset(1))
.Name = "importCSVimporter"
.FieldNames = True
.AdjustColumnWidth = True
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = True
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = column_types
.Refresh BackgroundQuery:=False
End With
ActiveWorkbook.Sheets(2).QueryTables(1).Delete
'If this line doesn't work, try (0) instead of (1)
'Declare variables
Dim ws1 As Worksheet
Dim ws2 As Worksheet
'Set variables to the worksheets
Set ws1 = Sheets("sheet2")
Set ws2 = Sheets("transactions")
'Copy
ws1.Range("A2", ws1.Range("a" & Rows.Count).End(xlUp).Offset(1)).Copy
'Paste
ws2.Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
'Copy
ws1.Range("b2", ws1.Range("b" & Rows.Count).End(xlUp).Offset(1)).Copy
'Paste
ws2.Range("c" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
'Copy
ws1.Range("c2", ws1.Range("c" & Rows.Count).End(xlUp).Offset(1)).Copy
'Paste
ws2.Range("d" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
'
Application.CutCopyMode = False
ws1.Range("A2", ws1.Range("T" & Rows.Count).End(xlUp).Offset(1)).Delete
End Sub
this works if I want to paste in same columns as original but I want column A from worksheet2 in column A in transactions sheet. Column B from Sheet 2 to column C in transactions sheet
VBA Code:
'Copy
ws1.Range("A2", ws1.Range("f" & Rows.Count).End(xlUp).Offset(1)).Copy
'Paste
ws2.Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues