+ Reply to Thread
Results 1 to 3 of 3

Macro for IF THEN conditions with Dynamic row range

Hybrid View

  1. #1
    Registered User
    Join Date
    11-17-2011
    Location
    Sri lanka
    MS-Off Ver
    Excel 2003
    Posts
    34

    Unhappy Macro for IF THEN conditions with Dynamic row range

    hello,

    i need to automate some manual works using Macro.
    here i have attached the relevant excel sheet : if conditions.xlsx

    here number of rows are not a fixed,it may change day by day and i have to run macro every day.since macro should identify the number of rows (that's the most difficult part for me with my little macro knowledge)
    let assume that row index is i (ith row)

    if Bi="IH"
    then
    Ii=Si , Ji=Ti ,Ki=Ui,Li=Vi ,Mi=Wi , Ni=Xi ,Oi=Yi

    if (date of Ai= date of Bi)
    then
    Ii=Si , Ji=Ti ,Ki=Ui,Li=Vi ,Mi=Wi , Ni=Xi ,Oi=Yi

    if Bi= "Transfer"
    then
    Ii=Si , Ji=Ti ,Ki=Ui,Li=Vi ,Mi=Wi , Ni=Xi ,Oi=Yi

    if Bi= "Hold" or "Update next week"
    then
    Ii=Ji=Ki=Li="TBA"

    if Ai="Update next week" and Bi=Di
    then
    Ii=Ji=Ki=Bi and Li="Achievable"

    else

    I,J,K,L,M,N,O should be empty cells(no need to change )


    hope i will get a help from you to overcome this problem
    thanks very much

  2. #2
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Macro for IF THEN conditions with Dynamic row range

    Hi rsami,

    try this :
    Sub test()
    Dim cell As Range, cr%
    
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    Application.EnableEvents = False
    
    
    For Each cell In Range("B3:B" & Range("B65536").End(xlUp).Row)
    cr = cell.Row
    
    If cell.Value = "IH" Or cell.Value = "Transfer" Or cell.Offset(0, -1).Value = cell.Value Then
    Range("I" & cr).Value = Range("S" & cr).Value
    Range("J" & cr).Value = Range("T" & cr).Value
    Range("K" & cr).Value = Range("U" & cr).Value
    Range("L" & cr).Value = Range("V" & cr).Value
    Range("M" & cr).Value = Range("W" & cr).Value
    Range("N" & cr).Value = Range("X" & cr).Value
    Range("O" & cr).Value = Range("Y" & cr).Value
    GoTo nxt
    End If
    
    If cell.Value = "Hold" Or cell.Value = "Update next week" Then
    Range("I" & cr & ":L" & cr).Value = "TBA"
    GoTo nxt
    End If
    
    If Range("A" & cr).Value = "Update next week" And cell.Value = Range("D" & cr).Value Then
    Range("I" & cr & ":K" & cr).Value = cell.Value
    Range("L" & cr).Value = "Achievable"
    GoTo nxt
    End If
    
    Range("I" & cr & ":O" & cr).Value = ""
     
    nxt:
    Next cell
    
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
    Application.EnableEvents = True
    
    End Sub
    Please click the * below if this helps
    Please click the * below if this helps

  3. #3
    Registered User
    Join Date
    11-17-2011
    Location
    Sri lanka
    MS-Off Ver
    Excel 2003
    Posts
    34

    Re: Macro for IF THEN conditions with Dynamic row range

    Hi JasperD

    sorry for the late reply.
    thanks very much for your help and it works perfectly.
    i added you Reputation

    thanks again

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1