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
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
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
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.
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.
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.
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
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.
Thank a lot
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