Insert Formula with VBA

methode2404

New Member
Joined
Sep 3, 2018
Messages
30
Hi,

I will insert this formula to cell with VBA

=COUNTIFS('today'!C:C;OOS_daily!G1;'today'!G:G;0;'today'!D:D;"<>N";'today'!O:O;0;'today'!P:P;">0")

I try this;

Sub test()
'
' test Macro
'


'
Columns("G:G").Select
ActiveSheet.Range("$G$1:$G$50000").RemoveDuplicates Columns:=1, Header:=xlNo
Range("H1").Select
Worksheets("OSS_daily").Range("H1").Formula = "=COUNTIFS('today'!C:C;OOS_daily!G1;'today'!G:G;0;'today'!D:D;""<>N"";'today'!O:O;0;'today'!P:P;"">0"")"

End Sub

I get the error message : run-time error '9': (for the last line)

can someone tell me where the problem is ?

Best Regards
Metin
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Do you have a sheet called OSS_daily? or should it be OOS_daily?
 
Upvote 0
I have changed the error in formula;

Columns("G:G").Select
ActiveSheet.Range("$G$1:$G$50000").RemoveDuplicates Columns:=1, Header:=xlNo
Range("H1").Select

Worksheets("OOS_daily").Range("H1").Formula = "=COUNTIFS('today'!C:C;OOS_daily!G1;'today'!G:G;0;'today'!D:D;""<>N"";'today'!O:O;0;'today'!P:P;"">0"")"

Bu i get now; run-time error '1004' application-defined or object-defined error
 
Upvote 0
Try changing the semi-colons in the formula to commas.
 
Upvote 0
Another quick questions,


With this part of code, i delete all cells that contains "0"


For Each cell In Range("G1:H1000")
If cell.Value = "0" Then cell.Clear
Next

The zero's are in column H
In Column G are the barcode number

When its deleted the zero in H, it's should delete the left cell too.

Is that possible ?
 
Upvote 0
Try...

Code:
    Dim mycell As Range
    For Each mycell In Range("H1:H1000")
        If mycell.Value = 0 Then mycell.Offset(, -1).Resize(1, 2).Clear
    Next
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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