Announcement

Collapse
No announcement yet.

Object required error when using variable in sub formula

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Object required error when using variable in sub formula



    Greetings!

    I'm at my wits end with this one...

    I'm passing a value entered from a textbox on my Excel sheet (see code below) ....

    Code:
    Public Sub TextBox1_Change()
    
    Dim DaysToCompletion As Integer
    DaysToCompletion = TextBox1.Value
    Call v_GetDaysToCompletion(DaysToCompletion) (Calls sub routine)
    
    End Sub
    So I'm passing the value to from "DaysToCompletion" this sub routine below and I'm trying to use the value stored in the variable in the formula below to be placed in cell "D19". However, I'm getting an error when the program hits the formula where I'm trying to subtract cell A19 from cell B19 and add the value of the variable "DaysToCompletion"..

    Any help will be greatly appreciated

    Code:
    Sub v_GetDaysToCompletion(ByVal DaysToCompletion As Integer)
    
    wksTarget.Range("D19").Value = "=(B19-A19) + DaysToCompletion"
    
    With wksTarget.Range("A18").CurrentRegion
    Set rngTarget = .Offset(1).Resize(.Rows.Count - 1)
    End With
    
    rngTarget.Columns(4).FillDown
    
    wksTarget.Range("A18:D18").Font.Bold = True
    
    Application.CutCopyMode = False
    
    End Sub





    Last edited by StephenR; 2 weeks ago. Reason: add code tags

  • #2
    Please use code tags in future as per forum rules.

    Think you just need
    Code:
    wksTarget.Range("D19").Value = "=(B19-A19) + " & DaysToCompletion
    Anything in quotes will appear literally.

    Comment


    • #3


      Thank you. It's working...

      Comment

      Working...
      X