VBA keeps giving run time error'1004': Application defined or object defined error for the code snippet below;
Sub deneme()
Dim a As Long
Dim b As Integer
For a = 12 To 13
For b = 2 To 3
Sheets(2).Select
ActiveSheet.Cells(a, 1).Select
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = Worksheets(2).Cells(a, 1).Value & " " & Left(Worksheets(2).Cells(a, 2).Value, 18)
ActiveSheet.Range("A1:D1").Select
Selection.Merge
ActiveCell.Select
ActiveCell.FormulaR1C1 = Worksheets(2).Cells(a, 1).Value
With Selection
.HorizontalAlignment = xlCenter
End With
Sheets(Sheets.Count).Select
ActiveSheet.Range(Cells(b, 1), Cells(b, 2)).Select
Selection.Merge
ActiveCell.Select
ActiveCell.FormulaR1C1 = Worksheets(2).Cells(8, b + 1)
With Selection
.HorizontalAlignment = xlCenter
End With
ActiveSheet.Range(Cells(b, 3), Cells(b, 4)).Select
Selection.Merge
ActiveCell.Select
ActiveCell.FormulaR1C1 = Worksheets(2).Cells(a, b + 1).Value
With Selection
.HorizontalAlignment = xlCenter
End With
Next b
Next a
End Sub
Two different variables a and b is working normally when seperated, however when i wrote them down together vba gives 1004 error.
I use the code for taking different values and arranging them in a new worksheet. This is only a small part of it which was working normally before.