VBA IF function with If True add one workday to previous row cell

hansgrandia

Board Regular
Joined
Jan 10, 2015
Messages
53
Hello,

I'm trying to embed an If function in VBA code but get stuck with several elements of the piece code (functions / brackets etc). The correct code for cell I2 would be =IF(H2=H1;WORKDAY(I1;1);F2)
Could someone help me to build this specific line of the code? Appreciated! Hans Grandia (Netherlands)

For i = 2 To LastRow Cells(i, 9) = IIf(ActiveCell= ActiveCell(-1,0)... Next i

In below standing complete code

VBA Code:
Sub Add_Business_days()

Dim String1 As String
Dim String2 As String
Dim full_string As String

Application.ScreenUpdating = False

'Activeer sheet
Worksheets("AFAS_2").Activate

'insert column for calculation working days
Columns("H").Insert
Range("H1").Value = "Unique value"

'Determine Last_Row
With ActiveSheet
    LastRow = .Range("A1").SpecialCells(xlCellTypeLastCell).Row
End With

'Formula for Concatenate
For i = 2 To LastRow
String1 = Cells(i, 2).Value
String2 = Cells(i, 7).Value
    Cells(i, 8) = String1 & String2
Next i

'Add correct date in new column
Columns("I").Insert
Range("I1").Value = "Date"

For i = 2 To LastRow
Cells(i, 9) = IIf(ActiveCell= ActiveCell(-1,0)...
Next i

Application.ScreenUpdating = True

End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
How about
VBA Code:
For i = 2 To LastRow
   If Cells(i, 8) = Cells(i - 1, 8) Then
      Cells(i, 9) = Application.WorkDay(Cells(i - 1, 9), 1)
   Else
      Cells(i, 9) = Cells(i, 6)
   End If
Next i
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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