[Show all top banners]

wheels
Replies to this thread:

More by wheels
What people are reading
Subscribers
:: Subscribe
Back to: Computer/IT Refresh page to view new replies
 excel help
[VIEWED 6568 TIMES]
SAVE! for ease of future access.
Posted on 10-13-09 8:46 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 


Need some input from excel expert's.



I need to make a script in excel that
would search and insert location(address) of the file in column.


Such as if I insert file name : xyz (to
be searched) in A column it would generate the link in B column


Something like search function in
windows.


Is this possible in excel?



Thanks.



 
Posted on 10-14-09 8:17 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

you need to write vba code sth like this:

Createobject FileSystemObject say fso.

get file name using GetFileName method of fso

iterate through the returned file names and assign it to the column B cell

Alternatively u can just use Dir(path) function similarly without creating fso object.

U need to put this code in the change event of the worksheet.
Also to prevent any other change in the worksheet to trigger above action,
do a intersection check of the changed range and the target range of cells.

 
Posted on 10-14-09 10:31 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

You mean if you type "wheels" in column A1 it should appear in B1?

like:






    A    B
wheels wheels

Go to column B and type =A1 (what ever you have on column A1 will appear there)

Or if you want  to import sheet1(table) to sheet 2 table anywhere
copy the table (data) from Sheet1 and paste in Sheet2 and make sure you use link on the drop down..

it will look like this....      =Sheet1!$A$2

Unless I am not understanding your statement....



 
Posted on 10-17-09 10:19 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Here you go. This VBA function is a function that I use in one of my VBA programs. All I had to do was modify it slightly for your purposes. All you have to do is simply call the function like:
searchFile "*.txt", "c:\", False

Hope this helps



'Returns 1 on success           0 on Failure
'You can use wildcards also in the filename.
'   Ex: *.txt
'
'Note:     Don't do: searchFile "*.txt", "c:\", True  (Your computer might hang)
Function searchFile(file_name As String, path_to_search As String, look_in_sub_folders As Boolean)
    Dim perr, res_row_no, res_row_col
    Dim File_Path As String, out_file As String, title1 As String, add_extension As String, res_sheet_name As String
    Dim No_Of_Files As Integer, i As Integer
    
    On Error GoTo Err_searchFile
    title1 = "File Search v1.0"
    
    '**********************************************
    'You can modify these values
    '**********************************************
    res_sheet_name = "Sheet3"       'If you are in a different sheet, simply put the sheet name here
    res_row_no = 1  'Give the starting row number where you want the results displayed
    res_row_col = "a"   'Give the column where you want the results to be displayed
    '**********************************************
    '**********************************************

    'Don't modify
    res_row_col = Asc(UCase(res_row_col)) - 65 + 1

    'Search for the file
    With Application.FileSearch
        .NewSearch
        .LookIn = path_to_search
        .filename = file_name
        .SearchSubFolders = look_in_sub_folders
        .Execute
    
        No_Of_Files = .FoundFiles.Count
        If No_Of_Files <= 0 Then
            MsgBox "Sorry couldn't find " & file_name & " in " & path_to_search & ".", , title1
            GoTo failed_exit
        Else    'If the file(s) was found
            For i = 1 To No_Of_Files
               Worksheets(res_sheet_name).Cells(i + res_row_no - 1, res_row_col).Value = .FoundFiles(i)
            Next i
        End If
    End With
    searchFile = 1      'Success code
    Exit Function       'Sucessful exit of the function

Err_searchFile:
    perr = Err
    MsgBox "ERROR! Inside searchFile. " & Err.Description, , title1

failed_exit:
    searchFile = 0
End Function


 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 90 days
Recommended Popular Threads Controvertial Threads
TPS Re-registration case still pending ..
Toilet paper or water?
and it begins - on Day 1 Trump will begin operations to deport millions of undocumented immigrants
Tourist Visa - Seeking Suggestions and Guidance
From Trump “I will revoke TPS, and deport them back to their country.”
I hope all the fake Nepali refugee get deported
advanced parole
Sajha Poll: Who is your favorite Nepali actress?
ढ्याउ गर्दा दसैँको खसी गनाउच
To Sajha admin
Problems of Nepalese students in US
Mamta kafle bhatt is still missing
अरुणिमाले दोस्रो पोई भेट्टाइछिन्
MAGA denaturalization proposal!!
Are Nepalese cheapstakes?
Nepali Psycho
How to Retrieve a Copy of Domestic Violence Complaint???
wanna be ruled by stupid or an Idiot ?
All the Qatar ailines from Nepal canceled to USA
MAGA मार्का कुरा पढेर दिमाग नखपाउनुस !
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters