Help on IF THEN code

Chip87

New Member
Joined
Dec 12, 2019
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I am very knew to VBA, just starting actually. I am looking for a way to automate a report. What I am looking for is:

If Months(column A) is 12 and Days(column B) < 365 then Days +30,
If Months is 6 and Days < 180 then Days +30,
If Months is 3 and Days < 90 then Days +30,

so like for row 3, Months is 12 and Days is 344, I would like to get 344+30 = 374

I do not want to use a formula, this report is extensive and I want to create one macro to deal with it in one press of a button
smile.gif


I would really appreciate any help on this.

Thanks!
 

Attachments

  • Capture.JPG
    Capture.JPG
    22.6 KB · Views: 4

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Where are these new numbers going? Overwriting column B? Column C?
 
Upvote 0
Try
VBA Code:
With Range("A:A")
    With Range(.Cells(1,2, .Cells(1, Rows.Count).End(xlup)).Offset(0,2)
        .FormulaR1C1 = "=RC2 + IF(RC1=12, IF(RC2<365),1,0),0)"
        .Value = .Value
    End With
End With
 
Upvote 0
This would do an overwrite.

VBA Code:
With Sheets("Sheet2")
    lr = .Range("A" & .Rows.Count).End(xlUp).Row
    If lr > 1 Then
        arr = .Range("A2:B" & lr)
        For i = LBound(arr) To UBound(arr)
            Select Case arr(i, 1)
                Case 3: If arr(i, 2) < 90 Then arr(i, 2) = arr(i, 2) + 30
                Case 6: If arr(i, 2) < 180 Then arr(i, 2) = arr(i, 2) + 30
                Case 12: If arr(i, 2) < 365 Then arr(i, 2) = arr(i, 2) + 30
            End Select
            
        Next
        .Range("A2:B" & lr) = arr
    End If
End With
 
Upvote 0
Hi this is another style if you are interested
Code:
Sub change_day()
    Dim x As Double
    For x = 2 To Rows.Count
        If Cells(x, 1) = 12 And Cells(x, 2) < 365 Then
            Cells(x, 2) = Cells(x, 2) + 30
        ElseIf Cells(x, 1) = 6 And Cells(x, 2) < 180 Then
            Cells(x, 2) = Cells(x, 2) + 30
        ElseIf Cells(x, 1) = 3 And Cells(x, 2) < 90 Then
            Cells(x, 2) = Cells(x, 2) + 30
        End If
    Next x
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,241
Members
449,075
Latest member
staticfluids

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