Problem with VBA Loop

cfadr

New Member
Joined
Oct 17, 2019
Messages
28
Hi,

I want to loop through rows in my worksheet and compare the cell values in particular columns with other rows defining a variable as True or False (my segment_trigger variable below) if the values are the same or different.

I have written the following code but its giving me "Compile Error: Object Required" - can someone please tell me where I am going wrong?

Thanks


Sub segment_trigger_returns()
Application.ScreenUpdating = False
Dim segment_trigger As Boolean
Dim trade_date As Date
Set trade_date = Range("A4:A75617")
Dim i As Range
For Each i In trade_date.Rows
i.Cells(1, 3) = company_name_curperiod
i.Cells(-1, 3) = company_name_prevperiod
i.Cells(1, 10) = segments_curperiod
i.Cells(-1, 10) = segments_prevperiod
If company_name_curperiod = company_name_prevperiod And segments_curperiod <> segments_prevperiod Then
segment_trigger = True
Else: segment_trigger = False
Next
Application.ScreenUpdating = True

End Sub
 
It wasn't clear so I amended the code as follows and it tells me I am getting an error on line 18 which is sumall = sumall + alpha_1y(i, 1)
Try changing that line of code to this and see if it works correctly...

sumall = sumall + Val(alpha_1y(i, 1))
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Okay it appears to be because some of the values in alpha_1y are not numeric so I've tried to add the IsNumeric criteria but it's now telling the subscript is out of range?
Which line is this error coming up on. Please help us by giving us all the information about the error, ie. what the error is and what line it is on and if it is subscript out of range , hover over each variable using debug on the line and find out which varaible it is.
At this point you might be able to solve the probelm youself, but if not we can help
 
Upvote 0
Thanks for the help; I just resolved this by deleting the non numeric data and is working now
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,157
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