1

I want to copy data from excel to. Below is how I want to copy the data. For example I want to copy data in cell D4 of excel to A4 in .

"Excel ---> CSV "D4-->A4 "F4&all excluding the first character in G4-->B4 "K4-->E4 "L4-->F4 "N4-->G4 "P4-->I4 

Below is my code. It creates and populates the data as I need except that it does not delete the first character in G4 when copying to B4 in csv. Can someone tell me how i need to change my code to implement this.

Sub csvfile() Dim fs As Object Dim a As Object Dim lngRow As Long Dim X Set fs = CreateObject("Scripting.FileSystemObject") Set a = fs.CreateTextFile("C:\temp\" & Environ("username") & ".csv", True) X = Range([d4], Cells(Rows.Count, "P").End(xlUp)).Value2 For lngRow = 1 To UBound(X) - 15 a.writeline X(lngRow, 1) & "," & X(lngRow, 3) & X(lngRow, 4) & ",,," & X(lngRow, 8) & "," & X(lngRow, 9) & "," & X(lngRow, 11) & ",," & X(lngRow, 13) Next a.Close End Sub 

1 Answer 1

1

You can manipulate the fourth column (G) like so:

full code

Sub csvfile() Dim fs As Object Dim a As Object Dim lngRow As Long Dim X Set fs = CreateObject("Scripting.FileSystemObject") Set a = fs.CreateTextFile("C:\temp\" & Environ("username") & ".csv", True) X = Range([d4], Cells(Rows.Count, "P").End(xlUp)).Value2 For lngRow = 1 To UBound(X) - 15 If Len(X(lngRow, 4)) > 0 Then X(lngRow, 4) = Right$(X(lngRow, 4), Len(X(lngRow, 4)) - 1) a.writeline X(lngRow, 1) & "," & X(lngRow, 3) & X(lngRow, 4) & ",,," & X(lngRow, 8) & "," & X(lngRow, 9) & "," & X(lngRow, 11) & ",," & X(lngRow, 13) Next a.Close End Sub 
Sign up to request clarification or add additional context in comments.

3 Comments

It gives me a type mismatch.
fixed dodgey ). pls try again
says invalid procedure call or argument. Ive tried both ways.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.