Need to Check Something

  • Thread starter Thread starter alexm999
  • Start date Start date
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
 
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
 
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
 
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
 
Hi
change the line
if lcase(wks_1.name) <>lcase(test_value)
to
if lcase(left(wks_1.name,3)) <>lcase(test_value)
 
Back
Top