LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Modify RDB code with find and offset

Thank you. It works perfectly. I can't thank you enough. For me as a newbie
to the newsgroups getting an answer to this problem is terrific. I am
inspired by the whole process.

--
John Yab


"Joel" wrote:

from
SummWks.Range("A" & RwNum) = FileNameXls(FNum)
to
BaseName = FileNameXls(FNum)
BaseName = mid(BaseName,instrrev(BaseName,"\") + 1)
SummWks.Range("A" & RwNum) = BaseName


"John Yab" wrote:

Thanks Joel,

It's almost perfect now. The only minor thing left is that column A
populates with the full path. How do I trim it so it is just the file name?
(just from the last \ to the right end?
--
John Yab


"Joel" wrote:

I found two minor problems

1) I don't think your code wrote the filename in column A so I forgot to do
it.
2) I left a pie ce of you old code in themacro that was putting the formula
in the worksheet. I think my code was working and then your old code
over-wrote the data my code put in the workbook


Sub TagTeam_QA()
Dim FileNameXls As Variant
Dim SummWks As Worksheet
Dim ColNum As Integer
Dim myCell As Range, Rng As Range
Dim RwNum As Long, FNum As Long, FinalSlash As Long
Dim ShName As String, PathStr As String
Dim SheetCheck As String, JustFileName As String
Dim JustFolder As String

ShName = "QA" '<---- matches the name of the sheet to be searched
Set Rng = Range("D1,O20,O38") '<---- matches the specific cells to
'collect

'Select the files with GetOpenFilename
FileNameXls = Application.GetOpenFilename( _
filefilter:="Excel Files,*.xl*", _
MultiSelect:=True)

If IsArray(FileNameXls) = False Then
'do nothing

'Change ScreenUpdating and calculation to increase speed of macro
Else
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

'Add a new workbook with one sheet for the summary
Set SummWks = Workbooks.Add(1).Worksheets(1)

'The links to the first workbook will start in row 3
RwNum = 2

For FNum = LBound(FileNameXls) To UBound(FileNameXls)
ColNum = 1
RwNum = RwNum + 1
Set bk = Workbooks.Open(Filename:=FileNameXls(FNum))
SummWks.Range("A" & RwNum) = FileNameXls(FNum)
found = False
For Each sht In bk.Sheets
If sht.Name = ShName Then
found = True
Exit For
End If
Next sht

If found = False Then
'If the sheet named per first comment(QA)does not exist in
'the workbook the row color will be Yellow.
SummWks.Rows(RwNum).Interior.Color = vbYellow
Else
With bk.Sheets(ShName)
Set c = .Cells.Find(what:="Lot", _
LookIn:=xlValues, lookat:=xlPart)
If Not c Is Nothing Then
SummWks.Cells(RwNum, "B") = c.Offset(0, 2).Value
End If
colcount = 3
Set c = .Cells.Find(what:="Grand", _
LookIn:=xlValues, lookat:=xlPart)
If Not c Is Nothing Then
firstaddr = c.Address
Do

SummWks.Cells(RwNum, colcount) = c.Offset(0, 1).Value
colcount = colcount + 1
Set c = .Cells.FindNext(after:=c)
Loop While Not c Is Nothing And c.Address < firstaddr
End If

End With
End If

bk.Close savechanges:=False

Next FNum

With SummWks
'Add titles to columns and format to center some titles
.Range("A1") = "Workbook Name"
.Range("B1") = "Lot #"

' Use AutoFit to set the column width in the new workbook
.UsedRange.Columns.AutoFit
End With
End If
End Sub



"John Yab" wrote:

Hi Joel, Thanks for helping me. Unfortunately the code didn't work. Opening
the workbooks instead is okay. I changed 2 instances of "loot" to LookAt" and
then the code ran, but when I ran it, it returned 3 columns of zeros. I noted
that the part at the top still references the hard code of D1, O20, O38. The
first column for "Workbook Name" did not return any values. When I click in
the results in cell B3 for example the formula bar displays: =$D$1, so I
think it may be referening the sheet I am looking at instead of the sheets
from the searched files.
--
John Yab


"Joel" wrote:

I opened the workbooks which I think is simplier than your appoach of using
formulas. I couldn't think of a good way of doing a find on a closed
workbook. Try this

Sub TagTeam_QA()
Dim FileNameXls As Variant
Dim SummWks As Worksheet
Dim ColNum As Integer
Dim myCell As Range, Rng As Range
Dim RwNum As Long, FNum As Long, FinalSlash As Long
Dim ShName As String, PathStr As String
Dim SheetCheck As String, JustFileName As String
Dim JustFolder As String

ShName = "QA" '<---- matches the name of the sheet to be searched
Set Rng = Range("D1,O20,O38") '<---- matches the specific cells to
'collect

'Select the files with GetOpenFilename
FileNameXls = Application.GetOpenFilename( _
filefilter:="Excel Files,*.xl*", _
MultiSelect:=True)

If IsArray(FileNameXls) = False Then
'do nothing

'Change ScreenUpdating and calculation to increase speed of macro
Else
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

'Add a new workbook with one sheet for the summary
Set SummWks = Workbooks.Add(1).Worksheets(1)

'The links to the first workbook will start in row 3
RwNum = 2

For FNum = LBound(FileNameXls) To UBound(FileNameXls)
ColNum = 1
RwNum = RwNum + 1
Set bk = Workbooks.Open(Filename:=FileNameXls(FNum))
found = False
For Each sht In bk.Sheets
If sht.Name = ShName Then
found = True
Exit For
End If
Next sht

If found = False Then
'If the sheet named per first comment(QA)does not exist in
'the workbook the row color will be Yellow.
SummWks.Rows(RwNum).Interior.Color = vbYellow
Else
With bk.Sheets(ShName)
Set c = .Cells.Find(what:="Lot", _
LookIn:=xlValues, loot:=xlPart)
If Not c Is Nothing Then
SummWks.Cells(RwNum, "B") = c.Offset(0, 2).Value
End If
colcount = 3
Set c = .Cells.Find(what:="Grand", _
LookIn:=xlValues, loot:=xlPart)
If Not c Is Nothing Then
firstaddr = c.Address
Do

SummWks.Cells(RwNum, colcount) = c.Offset(0, 1).Value
colcount = colcount + 1
Set c = .Cells.FindNext(after:=c)
Loop While Not c Is Nothing And c.Address < firstaddr
End If

End With
For Each myCell In Rng.Cells
ColNum = ColNum + 1
SummWks.Cells(RwNum, ColNum).Formula = _
"=" & PathStr & myCell.Address
Next myCell
End If

bk.Close savechanges:=False

Next FNum

With SummWks
'Add titles to columns and format to center some titles
.Range("A1") = "Workbook Name"
.Range("B1") = "Lot #"

' Use AutoFit to set the column width in the new workbook
.UsedRange.Columns.AutoFit
End With
End If
End Sub



"John Yab" wrote:

Could someone help me to modify the appended code from Ron de Bruins web
site, please? The values I really want to obtain are shown in the code
(namely in D1,O20,O38) but rather than hard coding D1,O20,O38 I would like to
use €śfind€ť and then €śoffset€ť to obtain them and use the code of €śfind€ť and
€śoffset€ť to replace: €śSet Rng = Range("D1,O20,O38")€ť. To restate this:
I would like to €śfind€ť the text: €śLot*€ť (located in B1) then offset 2
columns to the right to arrive at D1
I would like to €śfind€ť the text: €śGrand*€ť (located in N20) then offset 1
column to the right to arrive at O20
I would like to €śfind€ť the text: €śGrand*€ť (located in N38) then offset 1
column to the right to arrive at O38
This would allow for someone typing one of the key words of €śLot€ť or €śGrand€ť
in a different cell but still return the value that is referenced by these
labels. Or if there is a better way than using €śfind€ť and €śoffset€ť then that
would be good too. The texts are actually: €śLot # :€ť and €śGrand Average:€ť but
I was thinking to search with a wild card, * as sometimes the text is typed
slightly different, eg: Avg instead of Average. I am using Excel 2007 with
Vista. This is my first newsgroup post. Thanks, John Yab.

Sub TagTeam_QA()
Dim FileNameXls As Variant
Dim SummWks As Worksheet
Dim ColNum As Integer
Dim myCell As Range, Rng As Range
Dim RwNum As Long, FNum As Long, FinalSlash As Long
Dim ShName As String, PathStr As String
Dim SheetCheck As String, JustFileName As String
Dim JustFolder As String

ShName = "QA" '<---- matches the name of the sheet to be searched
Set Rng = Range("D1,O20,O38") '<---- matches the specific cells to
collect

'Select the files with GetOpenFilename
FileNameXls = Application.GetOpenFilename(filefilter:="Excel Files,
*.xl*", MultiSelect:=True)

If IsArray(FileNameXls) = False Then
'do nothing

'Change ScreenUpdating and calculation to increase speed of macro
Else
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

'Add a new workbook with one sheet for the summary
Set SummWks = Workbooks.Add(1).Worksheets(1)

'The links to the first workbook will start in row 3
RwNum = 2

For FNum = LBound(FileNameXls) To UBound(FileNameXls)
ColNum = 1
RwNum = RwNum + 1
FinalSlash = InStrRev(FileNameXls(FNum), "\")
JustFileName = Mid(FileNameXls(FNum), FinalSlash + 1)
JustFolder = Left(FileNameXls(FNum), FinalSlash - 1)

 
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 modify my code to offset the defined range and repeat theprocedure instead of duplicating my code? [email protected] Excel Programming 4 May 29th 09 10:13 PM
Find, Copy offset to offset on other sheet, Run-time 1004. Finny[_3_] Excel Programming 10 December 7th 06 11:46 PM
Code to modify find/replace mcphc Excel Programming 3 June 30th 06 05:09 PM
Find and Display / Modify code Soniya Excel Programming 0 October 12th 04 01:10 PM
Modify Find Code Al[_6_] Excel Programming 1 July 15th 03 10:35 PM


All times are GMT +1. The time now is 10:29 PM.

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

About Us

"It's about Microsoft Excel"