Copy Cell E value every n rows in A if (X-Y)<0 or (X-Z)<0

Seb1991

New Member
Joined
Apr 22, 2023
Messages
20
Office Version
  1. 365
Platform
  1. Windows
Hi guys, hope you're all fine. I need some help with the following macro
I'd like to copy a value of E2 in column A of the same row (A2) , if (L7-L22<0) or (L7-L33<0), in loop, so E2 in A2, from E2 every 45 rows so E47 in E47, E92 in A92 etc..
This macro should work as long as there is a value in E column (E2, E47, E92....)
I tried several times before asking here but i failed

Can you help me out with this ? Thank you so much for your time and your help!
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Forget that :rolleyes:
I have 2 values of course, i didnt explained, in my job i need to daily check the stock i have to be more than my prevision or my preorder, so i want to know if i dont have the stock for the day and i need to cut some goods :D L7 is my daily stock, L22 preorders and L33 prevision. Im new in my company and i wanto to impress, since everyone here are old dinosaurs who still check data code by code xD no way im gonna waste half of my day doing that way
 
Upvote 0
I have 2 values of course, i didnt explained, in my job i need to daily check the stock i have to be more than my prevision or my preorder, so i want to know if i dont have the stock for the day and i need to cut some goods :D L7 is my daily stock, L22 preorders and L33 prevision. Im new in my company and i wanto to impress, since everyone here are old dinosaurs who still check data code by code xD no way im gonna waste half of my day doing that way
in case the value is negative, it means i don't have enough stock, that's why i want to copy the value E2 (the product code) in A so i can filter, remove the empty rows, so i'll have every code under stock, easy and fast, but im new into vba im still learning, that's why i asked for help, it's super cool that people with advanced knowledge help other people like me :D
 
Upvote 0
My gut feeling is that this is going to take a few goes to get right, but as a starting point, try the following on a copy of your worksheet. Change the worksheet name to whatever you call it.

VBA Code:
Option Explicit
Sub Seb1991_V1()
    Dim ws As Worksheet
    Set ws = Worksheets("Sheet1")   '<~~ *** Change to actual sheet name ***
    Dim LRow As Long
    LRow = ws.Cells(Rows.Count, "E").End(xlUp).Row
    
    Dim a, b, i As Long
    a = ws.Range("A2:L" & LRow + 32)
    ReDim b(1 To UBound(a, 1), 1 To 1)
    
    For i = 1 To LRow
        If a(i, 5) <> "" And (a(i + 5, 12) - a(i + 20, 12) < 0 Or a(i + 5, 12) - a(i + 31, 12) < 0) Then b(i, 1) = a(i, 5)
    Next i
    
    ws.Range("A2").Resize(UBound(b, 1)).Value = b
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,294
Messages
6,124,101
Members
449,142
Latest member
championbowler

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