VBA code to insert formula -

Josu

New Member
Joined
Mar 2, 2021
Messages
39
Office Version
  1. 2010
Platform
  1. Windows
I am having issue to make macro to insert formula. In other excel spreadsheet similar macro was working fine, but here I am having issues.
I want to insert formula to A25 and basically drag down until A75... Formula is =IF(OR(Data!C2=""),"",Data!C2)
I tried couple of options, but no luck. I have a feeling this is due to IF in formula
Can you help me please?
VBA Code:
Sub RunFormulaStores() 'inserting formula for workgroup
'Dim last_row As Long
Dim iRange As Range
Set iRange = Range("A25:A75")
'last_row = Cells(Rows.Count, 4).End(xlUp).Row
iRange.Formula = "=IF(OR(Data!C2=""""),"""",Data!C2))"
' for every " in excel formula need to add, also in ran-ge there is drag down until last row
Range("A25").AutoFill Destination:=Range("A25:A75") '& last_row)
End Sub
Or
VBA Code:
Sub x()
Dim ws As Worksheet
Set ws = Sheets("Settings")
ws.Activate
Range("A24").Formula = "=IF(OR(Data!C2=""""),"""",Data!C2))"
End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hi. You shouldn't need the OR part in the formula as you only have one condition to test (i.e.; if Data!C2=""). Either that or you're missing the other condition for the OR statement. The below should work for you if there's only one condition in the IF statement.

VBA Code:
Sub fillformula()

Range("A24:A75").Formula = "=IF(Data!C2="""",1,Data!C2)"

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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