What is wrong with my formula? (VBA)

Cuylaerts

New Member
Joined
May 30, 2017
Messages
39
Hello,

Formula :

Dim machines As String
Dim wk As Integer
Dim var As Integer
machines = "LB300"
wk = 1027
var = Application.WorksheetFunction.CountIfs(Sheets("Hoofd-Overzicht").Range("A:A"), "&wk&", Range("D:D"), "&machine&")
For x = 1 To ((Range("$F$3") - 1) / ActiveWorkbook.Worksheets("Ignore").Range("C20")) - (" &var& ")

i seem to get an error on the last part, after i entered the " -(" &var& ") " bit.
i can't seem to find out what the error is.
( the dim var formula is tested in the excel sheet and works)

Can anyone help me plz?

kind regards!
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Why are you putting the var variable in Quotes with & ?

Shouldn't that just be
For x = 1 To ((Range("$F$3") - 1) / ActiveWorkbook.Worksheets("Ignore").Range("C20")) - var
 
Upvote 0
Try
Code:
[B]For x = 1 To ((Range("$F$3") - 1) / ActiveWorkbook.Worksheets("Ignore").Range("C20")) - var[/B]
 
Upvote 0
if you want to substract the value of your var variable, you aren't using the good syntax.

For x = 1 To ((Range("$F$3") - 1) / ActiveWorkbook.Worksheets("Ignore").Range("C20")) - var

You don't need to put anything around a variable. VBA automatically consider it as an Integer by declaring it at the start.
 
Upvote 0
Because i was desperate :p. already tried with just " - var "
My error dissapears but then my code wont do what it has to do :

After the line its gonna copy rows. but the formula should check how many rows i already copied so it just copy the rows i need and not make duplicates.

maybe something wrong with my formula?
 
Upvote 0
More details: if my cell value is 5 then im gonna copy the row 5 times.
Now if i change my value to 6, then my line should be copy once, because i already have the 5 other lines.
that's what the countifs is for , if i enter that formula in the sheet i get 5 as result.
so in the formula below that i'm trying to say that the amount of copys should be minus 5 , = 1
i hope this is a bit clear.

Ty
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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