How do i generate a value in every 2000 rows in column A?

Waboku

New Member
Joined
Jul 8, 2016
Messages
45
Hello,

for something I am doing for my work it would be very efficient to be able to use control down to the next 2000th cell instead of scrolling down to it. If anyone knows how to generate a value in those cells please consider replying, I would really appreciate the help.

I would like to generate an "x" or a "0" for example every 2000 cells. So starting with Cell 1 in column A, then Cell 2001, then cell 4001 and so on for the entire column.

Thanks
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Something like this...

Code:
Sub Insert_Every_2000()
    Dim i As Long
    For i = 1 To 50000 Step 2000 'Change to suit
        Range("A" & i).Value = "X"
    Next i
End Sub
 
Last edited:
Upvote 0
Thanks Jeff. That worked. I'm sure it will save me a few days. It was also nice to use vba for the first time.
 
Upvote 0
Thanks Jeff. That worked. I'm sure it will save me a few days. It was also nice to use vba for the first time.
Here is another macro that you can consider for future use...
Code:
[table="width: 500"]
[tr]
	[td]Sub Xevery2000rows()
  Range("A1:A" & Rows.Count) = Evaluate("IF(MOD(ROW(A1:A" & Rows.Count & "),2000)=1,""X"","""")")
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
Here is another macro that you can consider for future use...
Code:
[table="width: 500"]
[tr]
	[td]Sub Xevery2000rows()
  Range("A1:A" & Rows.Count) = Evaluate("IF(MOD(ROW(A1:A" & Rows.Count & "),2000)=1,""X"","""")")
End Sub[/td]
[/tr]
[/table]
Actually, given the fixed range being covered by this macro, the code cam be compacted somewhat like this...
Code:
Sub Xevery2000rows()
  [A1:A1048576] = [IF(MOD(ROW(A1:A1048576),2000)=1,"Z","")]
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

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