autofill

GordonLS

Board Regular
Joined
May 28, 2021
Messages
89
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Good morning, here is my problem. I am struggling with maybe the last line of missing code. The code below populates w2 and w3 with "1" and "2" respective. It then selects the range I need (to the last row). I need the sequential numbering. In this case it would be "1" thru "8". However I can't get it to fill the range. Any ideas would be appreciated


Range("w2").Select
ActiveCell.FormulaR1C1 = "1"
Range("w3").Select
ActiveCell.FormulaR1C1 = "2"
Range("I1").Select
Selection.End(xlDown).Select
lastRow = ActiveCell.Row
Range("w2:w3").select
ActiveCell.Offset(0, 0).Range("A1:A" & (lastRow - 1)).Select
 
Yes, data is being added and removed prior to running the code you provided. The number of rows vary each day but the headers are static and the reference column for LR will always be the same, column "I" which I changed from "A".

A hundred or so lines of code prior to this:

Dim lr As Long

lr = Cells(Rows.Count, "I").End(xlUp).Row

Range("w2").Select
ActiveCell.FormulaR1C1 = "1"
Range("W2:W" & lr).Formula = "=Row()-1"
Range("W2:W" & lr).Value = Range("W2:W" & lr).Value
Range("x2").Select
ActiveCell.FormulaR1C1 = "1"
Range("x2:x" & lr).Formula = "=Row()-1"
Range("x2:x" & lr).Value = Range("x2:x" & lr).Value
Range("a1").Select
End Sub
 
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
So it would be important to have that last row calculation happen AFTER all the additions/removals are complete (I would recommend putting it right before the line where we are doing the autofill), and it is important to make sure that we have it look at a good column to accurately identify where the current data ends.
 
Upvote 0

Forum statistics

Threads
1,215,809
Messages
6,127,013
Members
449,351
Latest member
Sylvine

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