Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
sp123
 
Posts: n/a
Default 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   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Max
 
Posts: n/a
Default 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
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
Excel table to Word help needed!!! Urgent. Irn Bru Freak Excel Discussion (Misc queries) 2 February 3rd 06 07:04 PM
Urgent Help Needed: X axis to scale ffuh Charts and Charting in Excel 2 January 7th 06 12:03 AM
Urgent help needed! skarbanan Excel Worksheet Functions 23 December 30th 05 10:56 PM
Urgent help needed - floating segmented bar chart Jeff B Charts and Charting in Excel 1 October 14th 05 07:21 AM
Urgent Help needed - I need to stop a process that is running forever in Excel shadestreet Excel Discussion (Misc queries) 2 October 6th 05 09:59 PM


All times are GMT +1. The time now is 10:55 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"