Hi all,
I am new to Excel/VBA and would require your help.
I have stuck again somewhere and will be highly obliged if you can help me.
I have two worksheet
1. Import File Utility (Sheet A)
2. TeamCenterVsFileMapping (Sheet B)
In Sheet A there are five columns(File Path, File Type, Dataset Type, Dataset Name, Named Reference) and "Import" button. if user clicks on Import button and select any folder, then Filepath, Filetype, Dataset Name(i.e Filename) corresponding to all files are imported in the Sheet A's Cells. But i also need to import values corresponding to Dataset Type and Named Reference. These values are fetching from Sheet B i.e TeamCenterVsFileMapping.
There is a mapping of Filetype Vs Dataset Type Vs Named Reference in Sheet B just like:
FileType ---- DatasetType ---- NamedReference
------------------------------------------------
zip ---- zipAddress ---- MScompression
accdb ---- Access ---- MSAccess
jpeg ---- Image ---- Xyz
jpg ---- Image ---- XXX
pdf ---- Acrobat ---- YYY
No what i want for each filetype in Sheet A, it will search File Type in Sheet B and if it finds then copy the Dataset Type and Named Reference value from Sheet B to Sheet A.
i have been able to do it but its:
1. When i import files, these two values are not getting imported for all files (but for few files they are getting imported).
2. However if i import same folder second time then all fields and their value are getting imported.
See the code below -
Sub GetFileList()
-
ChDrive "M"
-
ChDir "M:\Certificates"
-
'Const cStartRow As Long = 2
-
Const cFPathCol As Long = 1
-
Const cExtentionCol As Long = 2
-
Const cDatasetType As Long = 3
-
Const cFNameCol As Long = 4
-
Const cNamedReference As Long = 5
-
Const cLog As Long = 6
-
-
Dim ThisFolder As String
-
Dim ThisFile As String
-
Dim FileName As String
-
Dim Extention As String
-
Dim i As Long
-
-
If SelectDirectoryOK(ThisFolder) Then
-
ThisFile = Dir(ThisFolder & "\*.*")
-
i = Cells(50000, cFPathCol).End(xlUp).Offset(1, 0).Row
-
'i = cStartRow
-
Do Until ThisFile = ""
-
-
FileName = Left(ThisFile, InStrRev(ThisFile, ".") - 1)
-
Extention = Mid(ThisFile, InStrRev(ThisFile, ".") + 1)
-
-
Cells(i, cFPathCol) = ThisFolder & "\" & FileName & "." & Extention
-
Cells(i, cExtentionCol) = Extention
-
Cells(i, cFNameCol) = FileName
-
Call CopyTeamCentreValue(Extention, i)
-
'Cells(i, cDatasetType) = DataSetValue(Extention, i)
-
'Cells(i, cNamedReference) = NamedReferenceFunction(Extention)
-
Cells(i, cLog) = "import.log"
-
i = i + 1
-
ThisFile = Dir
-
Loop
-
End If
-
End Sub
-
-
Function SelectDirectoryOK(ByRef Directory As String, Optional InitialPath As String = "") As Boolean
-
SelectDirectoryOK = False
-
-
With Application.FileDialog(msoFileDialogFolderPicker)
-
If InitialPath <> "" Then .InitialFileName = InitialPath
-
.Title = "Select File FOLDER"
-
.AllowMultiSelect = False
-
.Show
-
If .SelectedItems.Count = 0 Then Exit Function
-
Directory = .SelectedItems(1)
-
End With
-
-
SelectDirectoryOK = True
-
End Function
-
-
Sub CopyTeamCentreValue(Extention As String, i As Long)
-
'Copy cells of cols A,F,E,D from rows containing "Significant" in
-
'col D of the active worksheet (source sheet) to cols
-
'A,B,C,D of Sheet2 (destination sheet)
-
Dim DestSheet As Worksheet
-
Const cDatasetType As Long = 3
-
Const cNamedReference As Long = 5
-
Dim SourceSheet As Worksheet
-
Set DestSheet = Worksheets("Import File Utility")
-
Set SourceSheet = Worksheets("TeamCenterVsFileMapping")
-
-
Dim sRow As Long 'row index on source worksheet
-
Dim dRow As Long 'row index on destination worksheet
-
Dim sCount As Long
-
dRow = i
-
For sRow = 2 To Range("A65536").End(xlUp).Row
-
'use pattern matching to find "File Type" anywhere in cell
-
If SourceSheet.Cells(sRow, "A") = Extention Then
-
'copy cols A,F,E & D
-
'SourceSheet.Cells(sRow, "B").Copy Destination:=DestSheet.Cells(dRow, cDatasetType)
-
DestSheet.Cells(dRow, cDatasetType) = SourceSheet.Cells(sRow, "B")
-
'DestSheet.Cells(i, cNamedReference) = SourceSheet.Cells(sRow, "C")
-
End If
-
Next sRow
-
End Sub
-
-
@prashantdixit
Hi again
Not to short this asnswers all you problems but I suggest you change the bit of code - For sRow = 2 To Range("A65536").End(xlUp).Row
-
'use pattern matching to find "File Type" anywhere in cell
-
If SourceSheet.Cells(sRow, "A") = Extention Then
-
'copy cols A,F,E & D
-
'SourceSheet.Cells(sRow, "B").Copy Destination:=DestSheet.Cells(dRow, cDatasetType)
-
DestSheet.Cells(dRow, cDatasetType) = SourceSheet.Cells(sRow, "B")
-
'DestSheet.Cells(i, cNamedReference) = SourceSheet.Cells(sRow, "C")
-
End If
-
Next sRow
to this - For sRow = 2 To SourceSheet.Range("A65536").End(xlUp).Row
-
'use pattern matching to find "File Type" anywhere in cell
-
If Trim(UCase(SourceSheet.Cells(sRow, "A"))) = Trim(UCase(Extention)) Then
-
'copy cols A,F,E & D
-
'SourceSheet.Cells(sRow, "B").Copy Destination:=DestSheet.Cells(dRow, cDatasetType)
-
DestSheet.Cells(dRow, cDatasetType) = SourceSheet.Cells(sRow, "B")
-
'DestSheet.Cells(i, cNamedReference) = SourceSheet.Cells(sRow, "C")
-
End If
-
Next sRow
Using Trim() and UCase() will remove any ambiguity with leading and trailing spaces and make it case insensity.
I have also added the sourcesheet reference when finding the last row in the source sheet (as it was you were finding the last row in the currently active sheet, which is the destination sheet!).
Other than that, ity seem to work OK.
HTH
MTB
2 4121 @prashantdixit
Hi again
Not to short this asnswers all you problems but I suggest you change the bit of code - For sRow = 2 To Range("A65536").End(xlUp).Row
-
'use pattern matching to find "File Type" anywhere in cell
-
If SourceSheet.Cells(sRow, "A") = Extention Then
-
'copy cols A,F,E & D
-
'SourceSheet.Cells(sRow, "B").Copy Destination:=DestSheet.Cells(dRow, cDatasetType)
-
DestSheet.Cells(dRow, cDatasetType) = SourceSheet.Cells(sRow, "B")
-
'DestSheet.Cells(i, cNamedReference) = SourceSheet.Cells(sRow, "C")
-
End If
-
Next sRow
to this - For sRow = 2 To SourceSheet.Range("A65536").End(xlUp).Row
-
'use pattern matching to find "File Type" anywhere in cell
-
If Trim(UCase(SourceSheet.Cells(sRow, "A"))) = Trim(UCase(Extention)) Then
-
'copy cols A,F,E & D
-
'SourceSheet.Cells(sRow, "B").Copy Destination:=DestSheet.Cells(dRow, cDatasetType)
-
DestSheet.Cells(dRow, cDatasetType) = SourceSheet.Cells(sRow, "B")
-
'DestSheet.Cells(i, cNamedReference) = SourceSheet.Cells(sRow, "C")
-
End If
-
Next sRow
Using Trim() and UCase() will remove any ambiguity with leading and trailing spaces and make it case insensity.
I have also added the sourcesheet reference when finding the last row in the source sheet (as it was you were finding the last row in the currently active sheet, which is the destination sheet!).
Other than that, ity seem to work OK.
HTH
MTB
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Will |
last post by:
On the subject of Data Warehouses, Data Cubes & OLAP….
I would like to speak frankly about Data Warehouses, Data Cubes and
OLAP (on-line analytical processing). Has it dawned on anyone else...
|
by: sridevi |
last post by:
Hello
How to export data from ms-access database to excel worksheet using ASP.
mainly i need to export data to multiple worksheets. it is very urgent to
us.
i have a sample code which works...
|
by: jnb0012 |
last post by:
I am trying to run a query (in access) to retrieve information for
several centers. I need to put this in excel. I'm sure this is an
easy answer but I need the info for each center on it's own...
|
by: Weyhooi |
last post by:
Help ! please help! i can't find the way to insert a new
blank row into excel worksheet using C#. Example macro in
vb6 as below :
Rows("15:15").Select
Selection.Insert Shift:=xlDown
i have...
|
by: Alexander |
last post by:
Because it's impossible to Server.Transfer custom HttpHandlers I need
for workaround and search for Httphandler mapped to custom URI by hands.
Is it possible to find which Httphandler mapped to...
|
by: system55 |
last post by:
I need some help.... How can i create a program wherein it can copy a file about 2MB in size, into another file using the extended memory allocation???
Do i need to use some interrupt calls in dos??
|
by: =?Utf-8?B?R2Vvcmdl?= |
last post by:
Hello everyone,
I am learning how to use Excel to connect to other external data source
(like database). What I want to do is to develop a plug-in for Excel and
automatically access external...
|
by: Rowena P Porley |
last post by:
Hi everyone, I hope someone can help me out!
I have 2 tables with 2 related colums: CHARGE_BREAKDOWN with Approvalcode and td columns while MERCHANT_BANK has Appcode and trandate columns.
The...
|
by: crystalgal |
last post by:
Help. I am using Excel to enter in daily numbers in worksheet 2. I want to use vb (w/in excel) to create a command button in worksheet 1. I want to enter a date in a cell and click the command...
|
by: Mansi Shah |
last post by:
I have one gridview with one column,
and at runtime i m adding template columns to it.. now
i want to copy the whole grid to another because i want to add 2 more
column in between on a button...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |