TimeToCode
TimeToCode

Reputation: 943

Adding a formula to a cell from VBA code

I'm trying to put in a specific cell a formula via VBA Code.

This is my formula:

=CONCATENATE("SK-",IF(A5+1<1000,IF(A5+1>=10,CONCATENATE("0",A5+1),CONCATENATE("00",A5+1)),A5+1),"-",RIGHT(J8,LEN(J8)-2))

And i want to add the formula to a cell, but the error 1004 appears when I execute the code.

I'm trying this:

Sheets("Sheet1").Select
Range("J6").Formula = "=CONCATENATE('SK-',IF(A5+1<1000,IF(A5+1>=10,CONCATENATE('0',A5+1),CONCATENATE('00',A5+1)),A5+1),'-',RIGHT(J8,LEN(J8)-2))"

Any question post on comments!

Upvotes: 1

Views: 107

Answers (1)

Tim Edwards
Tim Edwards

Reputation: 1028

Sheets("Sheet1").Range("J6").Formula = "=CONCATENATE(""SK-"",IF(A5+1<1000,IF(A5+1>=10,CONCATENATE(""0"",A5+1),CONCATENATE(""00"",A5+1)),A5+1),""-"",RIGHT(J8,LEN(J8)-2))"

Upvotes: 4

Related Questions