VBA question - copying across numbers

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

Thanks in advance!

//////////////////////////////////////////////

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


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


End Sub
 
Last edited by a moderator:

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Forum statistics

Threads
1,215,352
Messages
6,124,453
Members
449,161
Latest member
NHOJ

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