Skipping rows in VBA

markusreyes2907

New Member
Joined
Jul 14, 2020
Messages
34
Office Version
  1. 2013
Platform
  1. Windows
Hi, I'm quite new to VBA and am trying to essentially build code that will generate a table via output from input boxes. I am doing fine except I can't figure how to set up the "y" axis of my table. Right now I have three input boxes, the first to enter the number of reps, the second the number of treatment groups, and the third the number of days for the study. input box one and two should impact the range "A6" to A... depending on the input. Essentially I want treatment groups (ex. 1, 2, 3, 4, and 5) to be spaced apart in The A column in reference to the number of reps, with an extra empty cell in between. So, if the user inputs 3 reps and 3 treatment groups "A6" should say 1, "A10" should say 2, and so "A14" should say 3. Below is some code I have, I've been getting close, but can't figure out the exact execution.

VBA Code:
Dim reps As Integer, i As Integer, trtmnt As Integer, j As Integer, spce As Integer

reps = InputBox("Number of reps", "Enter Here")
trtmnt = InputBox("Number of treatment groups", "Enter Here")
spce = reps + 1

For i = 1 To reps
Range("A6").Cells(j, 1).Offset(spce, 0).Value = j

For j = 1 To trtmnt


Next j

Next i

Thanks,

markusreyes2907
 
Last edited by a moderator:

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
How about
VBA Code:
Dim reps As Long, i As Long, trtmnt As Long, j As Long, Rws As Long

reps = InputBox("Number of reps", "Enter Here")
trtmnt = InputBox("Number of treatment groups", "Enter Here")
Rws = 6
For i = 1 To reps
   Range("A" & Rws).Value = i
   For j = 1 To trtmnt
      Range("B" & Rws) = j
      Rws = Rws + 1
   Next j
   Rws = Rws + 1
Next i
 
Upvote 0
How about
VBA Code:
Dim reps As Long, i As Long, trtmnt As Long, j As Long, Rws As Long

reps = InputBox("Number of reps", "Enter Here")
trtmnt = InputBox("Number of treatment groups", "Enter Here")
Rws = 6
For i = 1 To reps
   Range("A" & Rws).Value = i
   For j = 1 To trtmnt
      Range("B" & Rws) = j
      Rws = Rws + 1
   Next j
   Rws = Rws + 1
Next i

Almost exactly what I need, thank you! I got the spacing in the A column I was looking for. I don't need any numbers data in the B column as that's where my data will begin. I will tweak it and it should be perfect. Again as a beginner there is still a lot I need to learn and I appreciate your help.
 

Attachments

  • mrexcelpic.PNG
    mrexcelpic.PNG
    36.2 KB · Views: 1
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,687
Members
449,117
Latest member
Aaagu

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