PDA

View Full Version : help in excel



naikadit
11-19-2008, 03:33 PM
Hi guys I am new to vba and hence need your help all i want to do is to check the data in rbs_lookup file in all the files in one of the folder on my C drive and if it finds it it should give the name of the file where it found it. I dont know how to check all the files in a folder so need your help
here is what i did till now

Sub fetch_data()
Dim main_file As Workbook, rbs_lookup As Workbook
Dim i As Integer, j As Integer
Set main_file = Workbooks("RNC File.xls") 'i want this file to be all the
'files in a folder in c drive

Set rbs_lookup = Workbooks("RBS lookup")
Dim sloop As Long
Sheet(1).Activate
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
main_file.Activate
row_start = 1
collumn_start = 1
row_low1 = find_low(row_start, collumn_start)
rbs_lookup.Activate
row_low = find_low(row_start, collumn_start)
For i = 1 To row_low
For j = 1 To row_low1
If rbs_lookup.Sheets(1).Cells(i, 1) = main_file.sheets1.Cells(j, 1) Then
rbs_lookup.Sheets(1).Cells(2, 1) = main_file.Name 'name of the file

End Sub
this is to calculate the min number of rows

Public Function find_low(row As Long, collumn As Integer) As Integer
Dim count_low As Long
Dim row1 As Long
row1 = row
count_low = 1
Do
count_low = count_low + 1
row = row + 1
Loop While Cells(row, collumn) <> ""
row = row1
find_low = count_low
End Function


Edit Lucas: vba tags added to code.

lucas
11-19-2008, 04:00 PM
naikadit,
When posting code.....select the code and hit the vba button to format it as I have done to your code in your first post...

Kenneth Hobs
11-20-2008, 06:15 AM
It is not clear to me what you want.

This link shows various methods to get a list a filenames.
http://www.vbaexpress.com/forum/showthread.php?t=22245