Consulting

Results 1 to 3 of 3

Thread: Variable sheetname in formula

  1. #1
    VBAX Regular
    Joined
    Sep 2017
    Posts
    24
    Location

    Variable sheetname in formula

    Hi

    I am getting variable update required message when trying to pass activecell.value into a string variable to specify the sheet

    Basically I have a list of sheetnames in A:A and want to add a countif formula to D that counts YES in therespective sheetname for H:H

    I can loop down the list no problem but get stuck with how to put the sheet name in

    Dim sht As String
       With ActiveCell.Offset(0, 3)
        
             sht = ActiveCell.Value
            .Formula = "=Countif(sht!H:H,""Yes"")"
        End With
    It just puts sht! into the formula instead of the cell name of the sheet?

    Any help much appreciated, thanks

  2. #2
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    try this:
    .Formula = "=Countif(" & sht & "!H:H,""Yes"")"

  3. #3
    VBAX Regular
    Joined
    Sep 2017
    Posts
    24
    Location
    Ok, Im sure I tried that but it's working now

    Also I changed
    sht = ActiveCell.Value
    to

    sht = "'" & ActiveCell.Value & "'"
    Thank you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •