Small Paul
Board Regular
- Joined
- Jun 28, 2018
- Messages
- 118
Hi
I have a vba which starts with the following:
The idea is that A2 will be numbered 1. A3 will be numbered 1 or 2 depending on set criteria.
A2 numbers correctly.
However, when there is only 1 row of data, the VBA adds #VALUE ! to cell A3 and also changes cell A2 to the same error.
What change do I need to make so the VBA stops if there is only 1 row of data?
Note: Works perfectly when 2+ rows of data!
Any thoughts would be most welcome.
Cheers
Small Paul.
I have a vba which starts with the following:
HTML:
ActiveSheet.Name = "Salesforce Download"
Dim lastrow As Long
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Setmyrange = range("A2", "A" & Cells(Rows.Count, 1).End(xlUp).row)
Application.ScreenUpdating = False
Columns("A:A").Select
Selection.Insert shift:=xlToRight
Selection.Insert shift:=xlToRight
range("A1").Select
ActiveCell.FormulaR1C1 = "Worksheet Identifier: IFA Group, Account Name, Currency"
range("A2").Select
ActiveCell.FormulaR1C1 = "1"
range("A3").Select
lastrow = Cells(Rows.Count, "L").End(xlUp).row
'this following line changes column A to #VALUE! if only 1 line of data!!!!!
range("A3:A" & lastrow).FormulaR1C1=IF(AND(RC[30]>""None"",RC[30]=R[-1]C[30],RC[32]=R[-1]C[32]),R[-1]C,IF(AND(RC[30]=""None"",RC[31]=R[-1]C[31],RC[32]=R[-1]C[32]),R[-1]C,R[-1]C+1))"
The idea is that A2 will be numbered 1. A3 will be numbered 1 or 2 depending on set criteria.
A2 numbers correctly.
However, when there is only 1 row of data, the VBA adds #VALUE ! to cell A3 and also changes cell A2 to the same error.
What change do I need to make so the VBA stops if there is only 1 row of data?
Note: Works perfectly when 2+ rows of data!
Any thoughts would be most welcome.
Cheers
Small Paul.
Last edited: