Jump to next sheet if not found

  • Thread starter Thread starter Zurn
  • Start date Start date
Z

Zurn

Hello,


I'm trying to program a search the content of certain cells of tw
different sheets. When click on a button, program asks fo
RUN-nr...(=cellRun)
Then program has to search first in sheet one, when finding an empt
cell, the same search in sheet2. On the active cell, I run an othe
adjust program.


-Worksheets("sheet1").Activate
Range("C11:C12").Activate
Do While cellRun <> ActiveCell
ActiveCell.Offset(rowOffset:=24).Activate
If IsEmpty(ActiveCell) Then
Exit Do
End If
Loop-

Now my problem: If I work with a DO LOOP in a Do Loop, the progra
isn't working.


several attempts didn't work...I'm not willing to give up trying...bu
a little tip is always welcome
 
Dim sh1 as Worksheet, sh2 as Worksheet
Dim i as long, bFound as Boolean
bFound = False
set sh1 = Worksheets("Sheet1")
set sh2 = worksheets("Sheet2")
for i = 11 to 203 step 24
if isempty(sh.Cells(i,3)) then exit for
if sh1.Cells(i,3) = cellrun then
sh1.Activate
cells(i,3).Select
bfound = True
exit for
elseif sh1.Cells(i+1,3) = cellrun then
sh1.Activate
cells(i+1,3).Select
bFound = True
exit for
end if
Next
if not bFound then
for i = 11 to 203 step 24
if isempty(sh2.Cells(i,3)) then exit for
if sh.Cells(i,3) = cellrun then
sh2.Activate
cells(i,3).Select
bfound = True
exit for
elseif sh2.Cells(i+1,3) = cellrun then
sh.Activate
cells(i+1,3).Select
bFound = True
exit for
end if
Next
End if

if not bFound then
msgbox "Not found"
exit sub
End if
 

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

Back
Top