Need to Check Something

A

alexm999

I have 2 files: FILE1 and FILE2

File1 has a 5 worksheets that begin with 101, 102, 103, 104 & 105

I need a code that if in FILE2 cell C14 there is a 101 and I'm in FILE
worksheet 101 then it goes ahead and runs the rest of the macro, but i
im in FILE1 , worksheet 102 and it sees a 101 in FILE2 then it stop
and says WRONG FIL
 
F

Frank Kabel

Hi
try something like the following
sub foo()
dim wbk_1 as workbook
dim wbk_2 as workbook
dim wks_1 as worksheet
dim wks_2 as worksheet
dim test_value

set wbk_1 = workbooks("file1.xls")
set wks_1 = wbk_1.activesheet
set wbk_2 = workbooks("file2.xls")
set wks_2 = wbk_2.worksheets("sheet1")
test_value = wks_2.range("C14").value

if lcase(wks_1.name) <>lcase(test_value) then
msgbox "wrong sheet"
exit sub
end if
'your code comes here
end sub
 
A

alexm999

Thanks, you have me in the right direction... But, what if my workshee
is called 101NOW and 101-MAR

How can I have it just check for the 101 in the worksheet name
 
A

alexm999

Also, sometimes the check in the other file is not in C14 - it's alway
2 cells to the right from the word Location, heres what I have, how ca
i integrate it:

Set ofound = Cells.Find(WHAT:="LOCATION", _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=True)
If Not ofound Is Nothing Then
ofound.Activate
If Trim(ofound) = "DDC" Then
ActiveCell.Offset(rowOffset:=0, columnOffset:=2).Activat
 
F

Frank Kabel

Hi
change the line
if lcase(wks_1.name) <>lcase(test_value)
to
if lcase(left(wks_1.name,3)) <>lcase(test_value)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top