Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
sp123
 
Posts: n/a
Default Compare cells and Create a new File


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=508262

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I create a drop down list from non-adjacent cells brian m. Excel Discussion (Misc queries) 4 January 28th 06 03:02 PM
Create an Excel file using a macro Cillian Excel Discussion (Misc queries) 0 January 9th 06 06:32 PM
Using text in cells to build a link to within another file Jon Excel Discussion (Misc queries) 2 August 2nd 05 09:24 PM
How do I use 3 cells to create the string for a lookup function? Bencomo Excel Worksheet Functions 1 May 15th 05 07:17 AM
trying to create an (almost) circular formula between cells and data validated cells with lists KR Excel Worksheet Functions 0 May 12th 05 07:21 PM


All times are GMT +1. The time now is 08:49 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"