Data being Placed in Incorrect Cell

Boomdiddygop

New Member
Joined
Oct 3, 2013
Messages
5
Hi, my code is behaving in a way that I did not at all expect.

What I was hoping it would do is go down column A and then apply a label and add a value depending on what is in the cell. If the cell is empty, then it will get a label and then in column B, a number would be added. If the name already exists, then a number would be added to the existing value in column B.

What is happening is I get Error:1004 Application-defined or object-defined error. For some reason the label is also placed in cell E7.



Sheets("Fixture Counter").Activate
For Each c In Range("A2:A" & Range("A1").End(xlDown).Row)
If c.FormulaR1C1 = "" Then
ActiveCell.FormulaR1C1 = Label
ActiveCell.Offset(0, 1).Select
FixtureNumber = Sheets("Fixture Counter").Range(ActiveCell).Value
'Application-defined or object-defined error.

ActiveCell.FormulaR1C1 = FixtureNumber + Added
ElseIf c.FormulaR1C1 = Label Then
ActiveCell.Offset(0, 1).Select
FixtureNumber = Sheets("Fixture Counter").Range(ActiveCell).Value
'It hasn't gotten this far but I'm guessing the same error will occur here.
ActiveCell.FormulaR1C1 = FixtureNumber + Added
End If
Next


If anybody could help me with either problem it would be much appreciated.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Edit: I figured out the issue with the Label being placed in E7. It happened to be the cell I had selected when I ran the Macro. I changed the code from ActiveCell.FormulaR1C1 to c.FormulaR1C1.
The only issue I see now is with the Application-defined or object-defined error.
 
Upvote 0
I figured it out. In case anybody else has a similar problem this is what I got.

For Each c In Range("A1:A" & Range("A1").End(xlDown).Offset(1).Row)
If c.FormulaR1C1 = Label Then
c.Offset(0, 1).Select
FixtureNumber = ActiveCell.Value
ActiveCell.FormulaR1C1 = FixtureNumber + Added
Exit For
ElseIf c.FormulaR1C1 = "" Then
c.FormulaR1C1 = Label
c.Offset(0, 1).Select
FixtureNumber = ActiveCell.Value
ActiveCell.FormulaR1C1 = FixtureNumber + Added
End If
Next


The range creator at the top selected the bottom filled cell, not the bottom empty cell. Adding the offset fixed that problem.
The error I kept getting came from setting "Fixture Number" the way I would set a range of a specific cell. Using ActiveCell.Value does the same thing, but for the selected cell.

I hope this helps someone.
 
Upvote 0

Forum statistics

Threads
1,215,093
Messages
6,123,066
Members
449,090
Latest member
fragment

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