PDA

View Full Version : [SOLVED:] Can a Header



karey
12-08-2022, 09:13 PM
Can a header and add a formula in excel file using vba


Header (e.g, Find, Change)

3036930370

Kindly help me on this

Aussiebear
12-08-2022, 11:18 PM
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.

karey
12-08-2022, 11:24 PM
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.

Grade4.2
12-09-2022, 12:26 AM
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

Grade4.2
12-09-2022, 12:28 AM
OMG your reply had me in stitches. Not being mean, just unexpected and accurate.

karey
12-09-2022, 12:43 AM
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

Grade4.2
12-09-2022, 02:00 AM
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)"

karey
12-09-2022, 02:02 AM
Thank a lot :bow:

Aussiebear
12-09-2022, 05:26 AM
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.