Consulting

Results 1 to 9 of 9

Thread: Can a Header

  1. #1
    VBAX Regular
    Joined
    Jun 2021
    Posts
    6
    Location

    Can a Header

    Can a header and add a formula in excel file using vba


    Header (e.g, Find, Change)

    Input file.xlsxOutput file.xlsx

    Kindly help me on this

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Quote Originally Posted by karey View Post
    Can a header and add a formula in excel file using vba
    That's got to one of the worst explanations I've ever read on this forum, to describe an issue.

    Kindly help me on this
    Possibly, after you have another crack at defining the issue.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    VBAX Regular
    Joined
    Jun 2021
    Posts
    6
    Location
    need to add header like (e.g., Find in (A1 cell) and Change in (B1 cell)) as in the output file.

    after that insert formula as in A2 as in the output file.

  4. #4
    VBAX Regular
    Joined
    May 2018
    Location
    Sydney
    Posts
    57
    Location
    Sub AddHeaderAndFormula()
        Dim header1 As String
        header1 = "Find in"
    Dim header2 As String
        header2 = "Change in"
    Dim formula As String
        formula = "=SUM(A1:A10)"
    ' Add the first header to cell A1
        ActiveSheet.Range("A1").Value = header1
    ' Add the second header to cell B1
        ActiveSheet.Range("B1").Value = header2
    ' Add the formula to cell A2
        ActiveSheet.Range("A2").Formula = formula
    End Sub
    Last edited by Aussiebear; 12-09-2022 at 03:35 AM. Reason: Added code tags to supplied code
    If you only ever do what you can , you'll only ever be what you are.

  5. #5
    VBAX Regular
    Joined
    May 2018
    Location
    Sydney
    Posts
    57
    Location
    OMG your reply had me in stitches. Not being mean, just unexpected and accurate.
    If you only ever do what you can , you'll only ever be what you are.

  6. #6
    VBAX Regular
    Joined
    Jun 2021
    Posts
    6
    Location
    Sub AddHeaderAndFormula()
    Dim header1 As String
    header1 = "Find in"
    
    
    Dim header2 As String
    header2 = "Change in"
    
    
    Dim formula As String
    formula = "=SUM(A1:A10)"
    
    
    ' Add the first header to cell A1
    ActiveSheet.Range("A1").Value = header1
    
    
    ' Add the second header to cell B1
    ActiveSheet.Range("B1").Value = header2
    
    
    ' Add the formula to cell A2
    ActiveSheet.Range("A2").Formula = "=INDEX({"IFig";"SFig";"Fig";"CFig"},MATCH(MID(LEFT(B2,FIND(".",$B2)-1),10,1),{"a";"s";"f";"c"},0)) & VALUE(MID(LEFT(B2,FIND(".",$B2)-1),11,2)) & MID(LEFT(B2,FIND(".",$B2)-1),13,99)"
    End Sub

    while add a formula syntax error comes how to solve this

  7. #7
    VBAX Regular
    Joined
    May 2018
    Location
    Sydney
    Posts
    57
    Location
    To fix the syntax error, you will need to add quotation marks around the elements in the arrays used in the INDEX and MATCH functions. Here is the corrected code:

    ActiveSheet.Range("A2").Formula = "=INDEX({""IFig"";""SFig"";""Fig"";""CFig""},MATCH(MID(LEFT(B2,FIND(""."",$ B2)-1),10,1),{""a"";""s"";""f"";""c""},0)) & VALUE(MID(LEFT(B2,FIND(""."",$B2)-1),11,2)) & MID(LEFT(B2,FIND(""."",$B2)-1),13,99)"
    If you only ever do what you can , you'll only ever be what you are.

  8. #8
    VBAX Regular
    Joined
    Jun 2021
    Posts
    6
    Location
    Thank a lot

  9. #9
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Quote Originally Posted by Grade4.2 View Post
    OMG your reply had me in stitches. Not being mean, just unexpected and accurate.
    You are right as it's not intended to be mean. However it's extremely frustrating when people post an issue without clearly defining the task at hand and the issue contained within. The members here who go to the trouble to assist others should not be cryptic mentalists, because others failed to offer a reasonable explanation of the problem. Members also, should not have to download files from people they have never had dealings with before, just to determine the task at hand.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

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