How do I code this?

Puppies72

Board Regular
Joined
Mar 29, 2010
Messages
211
I have tried to do this myself but even though it is very straightforward in plain English it is way beyond my skill level even with using online tutorials etc. Can someone put this into code please?

What I need the macro to do:

If !Validator BS7 > 0 AND If !Validator DG7 = ‘@depot’<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
then<o:p></o:p>
If !Validator BT7 < !Validator CA7 <o:p></o:p>
then <o:p></o:p>
if !Ships $Q$6 > 0 add 1 to !Validator BT7 and subtract 1 from !Ships $Q$6 until either !Validator BT7 = !Validator CA7 OR !Ships $Q$6 = 0<o:p></o:p>
then <o:p></o:p>
If !Validator BU7 < !Validator CB7 <o:p></o:p>
then <o:p></o:p>
if !Ships $R$6 > 0 add 1 to !Validator BU7 and subtract 1 from !Ships $R$6 until either !Validator BU7 = !Validator CB7 OR !Ships $R$6 = 0<o:p></o:p>
then<o:p></o:p>
If !Validator BV7 < !Validator CC7 <o:p></o:p>
then <o:p></o:p>
if !Ships $S$6 > 0 add 1 to !Validator BV7 and subtract 1 from !Ships $S$6 until either !Validator BV7 = !Validator CC7 OR !Ships $S$6 = 0<o:p></o:p>
then <o:p></o:p>
If !Validator BW7 < !Validator CD7 <o:p></o:p>
then <o:p></o:p>
if !Ships $T$6 > 0 add 1 to !Validator BW7 and subtract 1 from !Ships $T$6 until either !Validator BWT7 = !Validator CD7 OR !Ships $T$6 = 0<o:p></o:p>
then<o:p></o:p>
If !Validator BX7 < !Validator CE7 <o:p></o:p>
then <o:p></o:p>
if !Ships $U$6 > 0 add 1 to !Validator BX7 and subtract 1 from !Ships $U$6 until either !Validator BX7 = !Validator CE7 OR !Ships $U$6 = 0<o:p></o:p>
then<o:p></o:p>
If !Validator BZ7 < !Validator CG7 <o:p></o:p>
then <o:p></o:p>
if !Ships $W$6 > 0 add 1 to !Validator BZ7 and subtract 1 from !Ships $W$6 until either !Validator BZ7 = !Validator CG7 OR !Ships $W$6 = 0<o:p></o:p>
then <o:p></o:p>
start again with !Validator BS8<o:p></o:p>
<o:p></o:p>
notes<o:p></o:p>
<o:p></o:p>
If !Validator BS7 is 0 or blank OR DG7 does not equal ‘@depot’ then do nothing<o:p></o:p>
At any other point where the value in !Ships = 0 OR the value in the two !Validator cells are equal do next<o:p></o:p>
The values mention for !Ship are fixed and won't change through the macro loop - i.e. even though the row in validator increments the row in ships never will<o:p></o:p>
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
I'll start you off.
Code:
[SIZE=3][FONT=Calibri]If !Validator BS7 > 0 [B]AND[/B] If !Validator DG7 = ‘@depot’<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]then<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]If !Validator BT7 < !Validator CA7 <o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]then <o:p></o:p>[/FONT][/SIZE]
would be coded:-
Code:
[FONT=Fixedsys]If thisworkbook.sheets(Validator).range("BS7").value > 0 AND thisworkbook.sheets(Validator).range("DG7").value="@depot" then[/FONT]
[FONT=Fixedsys]    If thisworkbook.sheets(Validator).range("BT7").value < thisworkbook.sheets(Validator).range("CA7").value then <o:p></o:p>[/FONT]
Get the idea?

Can you proceed from there, using my example, until you get stuck again?
 
Last edited:
Upvote 0
Thanks Ruddles - before I start to get stuck into this do I need to declare any values or anything as once the initial checks have been made I need the entire thing to loop and increment a row

many thanks again
 
Upvote 0
If you're performing the loop only on rows 7 and 8, you need a variable to hold the row value, then you loop that variable from 7 to 8 - or to whatever other valus you want to end at - then instead of using 7 in your code, you use rowptr. So something like this:-
Code:
[FONT=Fixedsys]dim rowptr as long[/FONT]
 
[FONT=Fixedsys]for rowptr=7 to 8[/FONT]
[FONT=Fixedsys]    If thisworkbook.sheets(Validator).range("BS" & rowptr).value > 0 AND thisworkbook.sheets(Validator).range("DG" & rowptr).value="@depot" then
        If thisworkbook.sheets(Validator).range("BT" & rowptr).value < thisworkbook.sheets(Validator).range("CA" & rowptr).value then[/FONT]
[FONT=Fixedsys]..[/FONT]
[FONT=Fixedsys]etc.[/FONT]
[FONT=Fixedsys]next rowptr[/FONT]
 
Upvote 0
Hi again,

I've been looking at bits and bobs of code from other macros I have cobbled together in this workbook - do you think I could use something similar to this as I have to start at row 7 and then loop every row until I get to an empty one

Code:
Dim LR As Long, i As Long
 
LR = .Range("BS" & Rows.Count).End(xlUp).Row
    For i = 6 To LR
        With .Range("C" & i)
 
Upvote 0
That's a good start. Not sure you need the final line though, as this says "all the following code will refer to this range".

Also the dots (periods) imply that there has been a With statement before but we can't see one so perhaps:-
Code:
Dim LR As Long, i As Long
 
With Thisworkbook.Sheets(1)
  LR = .Range("BS" & .Rows.Count).End(xlUp).Row
      For i = 6 To LR
I'd suggest you start by practising with a small set of data in one column of a test worksheet, writing a loop to step through the rows and writing each value to the Immediate window (Ctrl-G) with the Debug.Print statement.

Become comfortable with the way the loop is set up and controlled, how to use the value of the loop variable (i in your example) to 'point to' the cells you're interested in and how to use the Range, Cells and Rows functions to select different parts of the worksheet.

Learning VBA can't be done overnight, but neither is it horrendously complex if you start with the simple stuff and build on what you know to get to the really tricky stuff.

And this board is always here to help when you get stuck!
 
Upvote 0
I'd be well and truly buggered if it wasn't for the wonderful people on this site :o)

Thank you so much
 
Upvote 0

Forum statistics

Threads
1,224,584
Messages
6,179,693
Members
452,938
Latest member
babeneker

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top