How to put the following formula on cells using VBA ?

Pramodpandit123

New Member
Joined
Apr 18, 2020
Messages
30
Office Version
  1. 2016
Platform
  1. Windows
I have a following formula on Excel cell that works fine but i want to put the formula on the cells using VBA .. Putting the formula using VBA gives me "Syntax error" during compiling.

Following is the formula that works on Excel cell :
Excel Formula:
=IF(I10="","",IF(I10=0,0,ROUND(MAX(IF((LEN(I10)-FIND(".",I10&"."))={-1,2},CONVERT(DOLLARDE(I10,12),"ft","m")),IFERROR(CONVERT(DOLLARDE(INT(I10)&".0"&MID(I10,FIND(".",I10)+1,1),12),"ft","m"),0)),2)))

Following is the VBA that gave me syntax error :
VBA Code:
.Range("U" & 3 + i).Formula = "=IF(I4="""","""",IF(I4=0,0,ROUND(MAX(IF((LEN(I4)-FIND(".",I4&"."))={-1,2},CONVERT(DOLLARDE(I4,12),"ft","m")),IFERROR(CONVERT(DOLLARDE(INT(I4)&".0"&MID(I4,FIND(".",I4)+1,1),12),"ft","m"),0)),2)))"

Following is the VBA that i want using Loop :
VBA Code:
For i=1 to 8
.Range("u" & 3 + i).Formula = "=IF(I" & 3+i & "="""","""",IF(I" & 3+i & "=0,0,ROUND(MAX(IF((LEN(I" & 3+i & ")-FIND(".",I" & 3+i & "&"."))={-1,2},CONVERT(DOLLARDE(I" & 3+i & ",12),"ft","m")),IFERROR(CONVERT(DOLLARDE(INT(I" & 3+i & ")&".0"&MID(I" & 3+i & ",FIND(".",I" & 3+i & ")+1,1),12),"ft","m"),0)),2)))"
Next
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
There seems to be little correlation between the post #1 code and the sample workbook.
Post 1 code puts the formulas in col U, sample book has them in col G
Post 1 has original data in col I, sample workbook has it is col C.
Post 1 has 8 rows of formulas, sample workbook has 4.

Assuming ..
- formulas in col U
- original data in I
- 8 rows of formulas
.. try this with a copy of your workbook

VBA Code:
Sub Test()
  Range("U4:U11").Formula = "=IF(I4="""","""",IF(I4=0,0,ROUND(MAX(IF((LEN(I4)-FIND(""."",I4&"".""))={-1,2},CONVERT(DOLLARDE(I4,12),""ft"",""m"")),IFERROR(CONVERT(DOLLARDE(INT(I4)&"".0""&MID(I4,FIND(""."",I4)+1,1),12),""ft"",""m""),0)),2)))"
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,614
Messages
6,120,517
Members
448,968
Latest member
Ajax40

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top