I'm having an issue with referring to multiple ranges using for loop. I created a set of ranges using standardized names like range_[number]. Unfortunately when i try to refer to them I constantly get errors or empty ranges.
Sub add_new_country()
'count initial number of countries
n = WorksheetFunction.CountA(Range("countries_list"))
'name of last country
last_country = Range("countries_list").Cells(n).Value
range_1 = ActiveWorkbook.Sheets("Countries").Columns(5).Cells
range_2 = ActiveWorkbook.Sheets("Operations").Columns(2).Cells
On Error Resume Next
For i = 1 To 2
Set active_range = Range("range_" & i)
For Each c In active_range
If c.Value = last_country Then
c.Offset(1).EntireRow.Insert
c.EntireRow.Cells.Copy
c.Offset(1).EntireRow.Cells.PasteSpecial Paste:=xlPasteFormats
c.Offset(1).EntireRow.Cells.PasteSpecial Paste:=xlPasteFormulas
c.Offset(1).EntireRow.SpecialCells(xlCellTypeConstants).ClearContents
End If
Next c
Next i
End Sub
Any ideas how to solve this?
Named Range? or you are trying to refere torange_1 = ActiveWorkbook.Sheets("Countries").Columns(5).Cells?