VBA Formula populating 1 too many rows

benntw

Board Regular
Joined
Feb 17, 2014
Messages
222
Office Version
  1. 365
Platform
  1. Windows
I have only one formula that is running one too many rows and can't figure out why. I use LastRow = Range("A" & Rows.count).End(xlUp).Row. This works for everything I am running in my VBA except one formula. I have a work order number and I am combining it with the formula to create an activity id for Primavera. Below is the formula. It works perfect except it goes one too many rows.

=I2&TEXT(100+(COUNTIFS(I$2:I2,I2)-1)*10,"-0000")

Hope someone can help out with something I missed on this.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
If you mean the formula is being entered into too many rows, it would help if you posted the code being used.
 
Upvote 0
If you mean the formula is being entered into too many rows, it would help if you posted the code being used.
This is the line of code that is going too far.


LastRow = Range("A" & Rows.cout).End(xlUp).Row

Range("R1").Value = "Activity Id"
Range("R2:R" & LastRow).Formula = "=RC[-9]&TEXT(100+(COUNTIFS(R2C[-9]:RC[-9],RC[-9])-1)*10,""-0000"")"
Range("R2:R" & LastRow).Copy
Range("R2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
 
Upvote 0
That works fine for me, although you can simplify slightly like
VBA Code:
LastRow = Range("A" & Rows.Count).End(xlUp).Row

Range("R1").Value = "Activity Id"
With Range("R2:R" & LastRow)
   .Formula = "=RC[-9]&TEXT(100+(COUNTIFS(R2C[-9]:RC[-9],RC[-9])-1)*10,""-0000"")"
   .Value = .Value
End With
Check what the value of lastrow is when you run the code.
 
Upvote 0
Solution
That works fine for me, although you can simplify slightly like
VBA Code:
LastRow = Range("A" & Rows.Count).End(xlUp).Row

Range("R1").Value = "Activity Id"
With Range("R2:R" & LastRow)
   .Formula = "=RC[-9]&TEXT(100+(COUNTIFS(R2C[-9]:RC[-9],RC[-9])-1)*10,""-0000"")"
   .Value = .Value
End With
Check what the value of lastrow is when you run the code.
Thank you very much. That worked perfect.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,575
Messages
6,125,620
Members
449,240
Latest member
lynnfromHGT

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