Need Help With the VBA .Formula Property With Variable

Landynsm

New Member
Joined
Aug 27, 2018
Messages
2
Guys/Gals,

I am trying to have the below code place a formula in Cells(lRow, 3) that contains variables. However, every time i try this it shows a #Name ? error. I have searched on this forum for additional help, but i can't get their solutions to work in my code. Can someone please show me the light??! Below is my latest attempt.


Code:
Dim lRow As Long
Dim ws As Worksheet
Dim wb As Workbook
Dim StatusCell As Range
Dim ElapsDays As Range
Dim CurDate As Range
Dim ProjDate As Range


Set ws = Worksheets(Cmbx_Project_Leaders.Value)
ws.Activate




lRow = Cells(Rows.Count, 2).End(xlUp).Row + 1


Set StatusCell = ws.Range("E" & lRow)
Set ElapsDays = ws.Range("C" & lRow)
Set CurDate = ws.Range("C3")
Set ProjDate = ws.Range("B" & lRow)


ws.Cells(lRow, 2).Value = txtb_Pj_srt_dt.Value
ws.Cells(lRow, 3).Formula = "=IF(OR(StatusCell.Address  =""Completed"",StatusCell.address=""""), """",CurDate.address - ProjDate.address )"
ws.Cells(lRow, 4).Value = Txtb_Project.Value
ws.Cells(lRow, 5).Value = Cmbx_Status.Value
ws.Cells(lRow, 7).Value = Txtb_Note.Value


MsgBox ("Entry successfully added!")
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hi & welcome to MrExcel
How about
Code:
Ws.Cells(lrow, 3).FormulaR1C1 = "=IF(OR(rc5=""Completed"",rc5=""""), """",r3c3 - rc[-1])"
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,270
Members
452,628
Latest member
dd2

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