Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
Urgent help needed
Hi, I am trying to check if a cell's value is present in another file, If so then i would like to copy it and another column from the same row(from the second file). Logic looks ok to me. But seems to be creating an empty file. Here is my code... Sub A1Compare() Dim consolidatedFile As String Dim allDeletesFile As String Dim myValue1 As String Dim myValue2 As String On Error GoTo ErrorHandling UserForm6.Show If UserForm6.fileName.Text = "" Or UserForm6.deleteFile.Text = "" Then Exit Sub Else consolidatedFile = UserForm6.fileName.Text allDeletesFile = UserForm6.deleteFile.Text End If Unload UserForm6 'Consolidated File Dim inputWorkBook1 As Workbook Dim inputWorkSheet1 As Worksheet Set inputWorkBook1 = Excel.Workbooks.Open(consolidatedFile) Set inputWorkSheet1 = inputWorkBook1.Worksheets(1) 'All Deletes file Dim inputWorkBook2 As Workbook Dim inputWorkSheet2 As Worksheet Set inputWorkBook2 = Excel.Workbooks.Open(allDeletesFile) Set inputWorkSheet2 = inputWorkBook2.Worksheets(1) 'New CSV files with Single Row Dim newWorkBook As Workbook Dim newWorkSheet As Worksheet Dim newCSVFile As String newCSVFile = Excel.ActiveWorkbook.Path + "\" + Left(Excel.ActiveWorkbook.Name, Len(Excel.ActiveWorkbook.Name) - 4) + "-DIFF_CSV.csv" Set newWorkBook = Workbooks.Add Set newWorkSheet = newWorkBook.Worksheets(1) Dim csvFileRowIndex As Integer 'Variable declarations Dim RowCountOfConsFile, RowCountOfDeleteFile, RowCountNewCSV As Integer Dim endFlag_ConsFile, endFlag_DeleteFile As Boolean 'Start parsing the files endFlag_ConsFile = False endFlag_DeleteFile = False RowCountOfConsFile = 2 RowCountOfDeleteFile = 1 RowCountNewCSV = 1 'Start parsing Do If inputWorkSheet1.Cells(RowCountOfConsFile, 1).value < "" Then endFlag_DeleteFile = False RowCountOfDeleteFile = 1 Do If inputWorkSheet2.Cells(RowCountOfDeleteFile, 1).value = inputWorkSheet2.Cells(RowCountOfDeleteFile, 6).value Then ' This is end of second file no match found !! Make an entry in new CSV ' Put the BUXpath uin new CSV & break out newWorkSheet.Cells(RowCountNewCSV, 1).value = inputWorkSheet2.Cells(RowCountOfDeleteFile, 1).value myValue1 = inputWorkSheet2.Cells(RowCountOfDeleteFile, 1).value MsgBox "step1" & myValue1 newWorkSheet.Cells(RowCountNewCSV, 2).value = inputWorkSheet2.Cells(RowCountOfDeleteFile, 6).value myValue2 = inputWorkSheet2.Cells(RowCountOfDeleteFile, 6).value MsgBox "step2" & myValue2 RowCountNewCSV = RowCountNewCSV + 1 endFlag_DeleteFile = True Else If inputWorkSheet1.Cells(RowCountOfConsFile, 1).value = inputWorkSheet2.Cells(RowCountOfDeleteFile, 1).value Then ' Oh matach found break out of the loop endFlag_DeleteFile = True End If End If RowCountOfDeleteFile = RowCountOfDeleteFile + 1 Loop While endFlag_DeleteFile = False Else endFlag_ConsFile = True End If RowCountOfConsFile = RowCountOfConsFile + 1 Loop While endFlag_ConsFile = False 'Save the new CSV On Error Resume Next newWorkBook.SaveAs newCSVFile, xlCSV newWorkBook.Close False Exit Sub ErrorHandling: MsgBox "Fatal error occoured !", vbCritical End Sub Thanks in advance for your help sp123 -- sp123 ------------------------------------------------------------------------ sp123's Profile: http://www.excelforum.com/member.php...o&userid=31163 View this thread: http://www.excelforum.com/showthread...hreadid=509145 |
#2
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
Urgent help needed
Perhaps its more appropriate to re-post your query in excel.programming ?
-- Max Singapore http://savefile.com/projects/236895 xdemechanik --- |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Excel table to Word help needed!!! Urgent. | Excel Discussion (Misc queries) | |||
Urgent Help Needed: X axis to scale | Charts and Charting in Excel | |||
Urgent help needed! | Excel Worksheet Functions | |||
Urgent help needed - floating segmented bar chart | Charts and Charting in Excel | |||
Urgent Help needed - I need to stop a process that is running forever in Excel | Excel Discussion (Misc queries) |