Excel VBA formula

Biz

Well-known Member
Joined
May 18, 2009
Messages
1,773
Office Version
  1. 2021
Platform
  1. Windows
Dear All,

Macro works well but I want streamline formula to remove reliance on column A. Not sure how to do this.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p> </o:p>
<o:p></o:p>
<o:p>
Code:
[SIZE=3][FONT=Calibri]Sub ShowWorkDays()<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]Dim i As Integer<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]Dim r As Long, NextRow As Long<o:p></o:p>[/FONT][/SIZE]
<o:p>[FONT=Calibri][SIZE=3] [/SIZE][/FONT]</o:p>
[SIZE=3][FONT=Calibri]'Fill Days<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]r = 1<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]For i = 1 To Range("S3").Value<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]    NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]    Cells(NextRow, 1) = i<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]    Cells(NextRow + 1, 1) = i<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]    r = r + 1<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]Next i<o:p></o:p>[/FONT][/SIZE]
<o:p>[FONT=Calibri][SIZE=3] [/SIZE][/FONT]</o:p>
[SIZE=3][FONT=Calibri]'Fill Formula for Workdays<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]With Range("B2:B" & (Range("S3").Value * 2) + 1)<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]    .Formula = _<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]        "=IF(WORKDAY(R1C[17]-1,RC1,dHolidays)>R2C[17],"" "",WORKDAY(R1C[17]-1,RC1,dHolidays))"<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]    .NumberFormat = "dd/mm/yyyy;@"<o:p></o:p>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]End With<o:p></o:p>[/FONT][/SIZE]
<o:p>[FONT=Calibri][SIZE=3] [/SIZE][/FONT]</o:p>
[SIZE=3][FONT=Calibri]End Sub<o:p></o:p>[/FONT][/SIZE]

I believe RC1 needs to be i but I don't know how to do this.
</o:p>
Reason why 1 day appears twice is because 1 record is from Home to Work and other is Work to Home.<o:p></o:p>

Any help would be greatly appreciated.

Biz
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
You have to explain what you mean by "I believe RC1 needs to be i" ... what do you want to the formula to do instead of referencing column A?
 
Upvote 0
Thanks I fixed it.

Code:
'Fill Formula for Workdays
Range("B2:B" & (Range("Workdays").Value * 2) + 1).Formula = _
        "=IF(WORKDAY(StartFY-1,$A2,dHolidays)>EndFY,"" "",WORKDAY(StartFY-1,$A2,dHolidays))"
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,740
Members
452,940
Latest member
Lawrenceiow

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