Log in

View Full Version : Create csv with appended data



dhivya.enjoy
10-23-2013, 01:31 PM
Hi Team,

I use the below code to create a csv file from the excel data which user enters. Now my issues is i need to check in that excel sheet(see attached) if column P has some value in a row the corresponding column A value need to be copied to the csv getting created by this code.Likewise i need to check all the rows of P and copy the corresponding A values to csv file. But what is happening is it is copying the last checked value frm excel to this csv instead of appending the data. Data is completely replaced. Atttached are both my csv and excel files. Please advise


13031304



strThirdCSVName = "Third"
strThirdTable = "RATE_GEO_COST_GROUP"

ThirdTable_Col1 = "RATE_GEO_GID" ' Naming the columns of the RATE_GEO_COST_GROUP CSV
ThirdTable_Col2 = "RATE_GEO_COST_GROUP_GID"


strCSV_3_Columns = "B" ' Let Say Columns D,F,H and Columns J to L



wbkNew.Sheets(1).Cells.Clear
strRange = MakeRange(strCSV_3_Columns)
.Range(strRange).Copy
wbkNew.Sheets(1).Range("A1").PasteSpecial xlPasteValuesAndNumberFormats
wbkNew.Sheets(1).Rows(1).Insert

wbkNew.Sheets(1).Cells(1).Value = strThirdTable


wbkNew.Sheets(1).Rows(2).Cells(1).Value = ThirdTable_Col1 'This line code will add additional column to csv
wbkNew.Sheets(1).Rows(2).Cells(2).Value = ThirdTable_Col2




Dim j As Integer
lastcell = Range("A" & Cells.Rows.Count).End(xlUp).Row
MsgBox lastcell
For j = 2 To lastcell
Rate_basis1 = UCase(wksAct.Cells(j, 16).Value)
RR_name = UCase(wksAct.Cells(j, 2).Value)

If Not (Rate_basis1 = "") Then

wbkNew.Sheets(1).Range("B3").Activate
For i = 3 To wbkNew.Sheets(1).Range("A1").End(xlDown).Row - 0
wbkNew.Sheets(1).Rows(i).Cells(1).Value = "GRK." & RR_name

wbkNew.Sheets(1).Rows(i).Cells(2).Value = "GRK." & Rate_basis1


Next i
wbkNew.Sheets(1).Range("A1").Activate

End If
Next j



Application.DisplayAlerts = False
wbkNew.SaveAs Filename:=strSaveLocation & strThirdCSVName, FileFormat:=xlCSV, CreateBackup:=False
Application.DisplayAlerts = True