vba question - Repeating sequence!

Status
Not open for further replies.

Number 1

New Member
Joined
Apr 19, 2018
Messages
3
Hi All,

I'm trying to get a macro to work.

The code I currently have is below. The code in bold does not work correctly

Ideally, I would like the macro to copy use the input from the "First year of issue" (e.g. 2016/17), and then duplicate it x times below (depending on the value of D27). It should then reduce down the number of tax years depending on the number of tax years of issue.

So, for example, if there were 3 employees, who had 3 tax years of issue, and the first tax year was 2012/13, then the macro should give me

2012/13
2012/13
2012/13
2013/14
2013/14
2013/14
2014/15
2014/15
2014/15

Thanks in advance!

Rich (BB code):
Sub Button11_Click()    
Rows("71").EntireRow.Hidden = False
    
  Dim x As Integer
    x = Range("f26").Value
  
Let RowRange = "72:" & 72 + x
Rows("72:72").Copy Range(RowRange)


  For i = 1 To x
        Let ControlIdRow = 71 + i
        Cells(ControlIdRow, 1).Value = "Employee ID" & i
        Cells(ControlIdRow, 2).Value = "[Insert employee name here]"
        Cells(ControlIdRow, 3).Value = "[Insert employee NINO here]"
        Cells(ControlIdRow, 4).Value = "[Tax year of issue]"
        Cells(ControlIdRow, 5).Value = "Insert amount due here for employee " & i
        Cells(ControlIdRow, 6).Value = "[Provide a description of the payment]"
        Cells(ControlIdRow, 7).Value = "[Select tax rate]"
       
Next i


Dim y As Integer


y = InputBox("Number of tax years of issue?")
If y = 1 Then
'do nothing


End If


If y > 1 Then


Range("A72").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy


Do Until y = 1
Range("A" & Rows.count).End(xlUp).Offset(1, 0).PasteSpecial
y = y - 1


Loop


Application.CutCopyMode = False


End If


Sheets("Input Sheet").Range("D72").Value = InputBox("Enter the first tax year of issue")


Dim Myvalue As Long


Myvalue = Range("f26").Value


Dim Fy As Long
Dim Ly As Long
Fy = Mid(D72, -2, 2)
Ly = Mid(D72, D72 + 1, 2)
Dim changeCounter As Long
Dim allEmp As Long
Dim P As Integer
P = 1
changeCounter = 0
For P = 1 To x
Dim integerhold As Integer
cell.Value = texttopaste
integerhold = "RoundUp(changeCounter / F26 + 1, 0)"
Next
If intgerhold <> P Then
Fy = Fy + 1
Ly = Ly + 1
cell.Value = texttopaste
End If


End Sub
 
Last edited by a moderator:

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Duplicate: https://www.mrexcel.com/forum/excel-questions/1052412-vba-question-copying-across-numbers.html

Please do not post the same question multiple times. All clarifications, follow-ups, and bumps should be posted back to the original thread. Per forum rules, posts of a duplicate nature will be locked or deleted (rule 12 here: Forum Rules).
If you do not receive a response, you can "bump" it by replying to it again, though we advise you to wait 24 hours before doing and not to bump a thread more than once a day.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

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