PC Review


Reply
Thread Tools Rate Thread

Check for >0, then offset down 310, left 4, Check for = 0

 
 
ryguy7272
Guest
Posts: n/a
 
      9th Dec 2009
I am trying to come up with a procedure that checks a Range(“E3:E300) and if
any value is >0 then Offset(310, -4) so I go down 310 rows and over to Column
A, and then look at the value in that cell. If the value in that cell is
equal to 0, then CALL A SUB in another module.

When the sub finishes, put a 1 in that cell, down 310 and over to the left
4. So, the next time I run this loop, if I checks a Range(“E3:E300) and if
any value is >0 then Offset(310, -4) so I go down 310 rows and over to Column
A, and then look at the value in that cell. If the value in that cell is
equal to 1, DON’T CALL THE SUB.

TIA!
Ryan--


--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.
 
Reply With Quote
 
 
 
 
OssieMac
Guest
Posts: n/a
 
      9th Dec 2009
Hi Ryan,

To the best of my testing CountIf(rng, ">0") > 0 only looks at numerics;
unlike testing for a cell >0 which returns all cells with anything at all in
them.

You did not specify from which cell you want the offset so I assumed E3.

Sub Call_If()

Dim ws1 As Worksheet
Dim rng As Range

Set ws1 = Sheets("Sheet1")

With ws1
Set rng = .Range("E3:E300")
End With

If WorksheetFunction.CountIf(rng, ">0") > 0 Then
If ws1.Range("E3").Offset(310, -4) = 0 Then
Call Asub
ws1.Range("E3").Offset(310, -4) = 1
End If
End If

End Sub


--
Regards,

OssieMac


 
Reply With Quote
 
marcus
Guest
Posts: n/a
 
      9th Dec 2009
Hi Ryan

This should do what you are after. Obvo change the variables to
suit. I tested it on a smaller range. But the principle is the same.

Take care

Marcus

Option Explicit
Sub Move()
Dim i As Integer

For i = 2 To 10
If Range("E" & i).Value > 0 Then
If Range("A" & i + 10).Value = 0 Then
Range("A" & i + 10).Value = 1
'Call YOURMACROHERE
End If
End If
Next i

End Sub
 
Reply With Quote
 
ryguy7272
Guest
Posts: n/a
 
      9th Dec 2009
Thanks OssieMac! That kind of worked; it worked for the first cell, which
had data in it, but it didn't work for any subsequent cells. I say kind of,
because if I enter data in E4 and E12 and E20, I see a ‘1’ in cell A312, but
no subsequent cells, and no sequence, like this…>0 in E5, E20, & E22, and a
‘1’ in A316 A332, & A334. That’s what I want to do. Also, and I know this
complicates things, but I want to call a private sub. I looked here
http://www.your-save-time-and-improv...ivate-sub.html

Seems like it can’t be done. Is it true? I have this:
Private Sub cmdSendBasket_Click()
‘stuff here…
End Sub

The private sub is in a sheet; linked to Active X button. Haw can I call
this from the Sub Call_If() macro? Or, how do I need to change my project to
make this work?

Thanks so much!
Ryan---


--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"OssieMac" wrote:

> Hi Ryan,
>
> To the best of my testing CountIf(rng, ">0") > 0 only looks at numerics;
> unlike testing for a cell >0 which returns all cells with anything at all in
> them.
>
> You did not specify from which cell you want the offset so I assumed E3.
>
> Sub Call_If()
>
> Dim ws1 As Worksheet
> Dim rng As Range
>
> Set ws1 = Sheets("Sheet1")
>
> With ws1
> Set rng = .Range("E3:E300")
> End With
>
> If WorksheetFunction.CountIf(rng, ">0") > 0 Then
> If ws1.Range("E3").Offset(310, -4) = 0 Then
> Call Asub
> ws1.Range("E3").Offset(310, -4) = 1
> End If
> End If
>
> End Sub
>
>
> --
> Regards,
>
> OssieMac
>
>

 
Reply With Quote
 
OssieMac
Guest
Posts: n/a
 
      9th Dec 2009
Hi again Ryan,

I think that I might have completely misunderstood the question. I thought
that you meant that if any cell in the range was greater than 0. If I now
interpret the question correctly you want to iterate through the cells and
check them one at a time and place the 1 in a cell offset from the cell being
tested. Is this correct? To do this, depending on whether all cells will be
numeric, you might need to test each cell if isnumeric as well as testing if
> 0 because cells with any character returns greater than zero. See code

below and see if that does what you want.

On the other question re calling a private sub. What I would do is place the
private subs code in a standard module and in the private sub have only one
line of code to call the sub in the standard module. You can then call that
code in the standard module from anywhere in your project.

Sub Call_If()

Dim ws1 As Worksheet
Dim rng As Range
Dim cel As Range

Set ws1 = Sheets("Sheet1")

With ws1
Set rng = .Range("E3:E300")
End With

For Each cel In rng
If IsNumeric(cel.Value) And cel.Value > 0 Then
Call Asub
cel.Offset(310, -4) = 1
End If
Next cel

End Sub

--
Regards,

OssieMac

 
Reply With Quote
 
OssieMac
Guest
Posts: n/a
 
      9th Dec 2009
My apologies Ryan I forgot to include the test for the offset cell in the If
statement. Try this instead.

Sub Call_If()

Dim ws1 As Worksheet
Dim rng As Range
Dim cel As Range

Set ws1 = Sheets("Sheet1")

With ws1
Set rng = .Range("E3:E300")
End With

For Each cel In rng
If IsNumeric(cel.Value) And _
cel.Value > 0 And _
cel.Offset(310, -4) <> 1 Then

Call Asub
cel.Offset(310, -4) = 1
End If
Next cel

End Sub

--
Regards,

OssieMac


 
Reply With Quote
 
ryguy7272
Guest
Posts: n/a
 
      9th Dec 2009
Perfect, perfect, perfect! I was going down the wrong path, but you got me
straightened out; headed in the right direction now.

Thanks so much!
Ryan---

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"OssieMac" wrote:

> My apologies Ryan I forgot to include the test for the offset cell in the If
> statement. Try this instead.
>
> Sub Call_If()
>
> Dim ws1 As Worksheet
> Dim rng As Range
> Dim cel As Range
>
> Set ws1 = Sheets("Sheet1")
>
> With ws1
> Set rng = .Range("E3:E300")
> End With
>
> For Each cel In rng
> If IsNumeric(cel.Value) And _
> cel.Value > 0 And _
> cel.Offset(310, -4) <> 1 Then
>
> Call Asub
> cel.Offset(310, -4) = 1
> End If
> Next cel
>
> End Sub
>
> --
> Regards,
>
> OssieMac
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check Box linked cell offset Tracey Microsoft Excel Programming 1 8th Feb 2010 08:59 AM
Check box appearing only if there is info in field to the left Dottie Microsoft Word Document Management 1 21st Nov 2009 06:54 AM
check.offset =?Utf-8?B?ZGF2ZW5mZQ==?= Microsoft Excel Programming 1 13th Jul 2007 02:14 AM
Can Vlookup check a cell to the left? koala Microsoft Excel Worksheet Functions 3 13th Jul 2005 02:31 AM
How to check the No Of Days left for Password Expiry Sudeep Microsoft Windows 2000 Active Directory 2 28th Jan 2004 07:07 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:41 PM.