Hi Everybody
I have defined name of range of cells B19 to B23 on sheet1 of excel workbook as SARbtRng and put some numeric values in these cells (e.g. 10000, 15000, 25000, 33000, 50000)
Again I have defined name of 5 cells on sheet 2 as under
Cell Name Defined
K9 SA1
K10 SA2
K11 SA3
K12 SA4
K13 SA5
All these names are defined in excel and till this point no vba command is used.
What I want to do is that to write a code which will pick values one by one from range SARbtRng and put these in corresponding cells on sheet2 i.e. It takes value from cell B19 (e.g 10000) and put it in the cell named SA1 (i.e. cell K9) on sheet 2 and then it take value from cell B20 (e.g. 15000) and put it in the cell named SA1 (i.e. cell K10) on sheet 2 and so on...
I am using the following code
Sub B()
For i = 1 To [SARbtRng].Rows.Count
SumAssuredi = "SumAssured" & i
SumAssured = [SARbtRng].Cells(i, 1).Value
Range("SumAssuredi") = SumAssured
Next i
End Sub
This gives the error "Method 'Range' of object '_global' failed.
Please suggest why this error is coming and what code should be used
I have defined name of range of cells B19 to B23 on sheet1 of excel workbook as SARbtRng and put some numeric values in these cells (e.g. 10000, 15000, 25000, 33000, 50000)
Again I have defined name of 5 cells on sheet 2 as under
Cell Name Defined
K9 SA1
K10 SA2
K11 SA3
K12 SA4
K13 SA5
All these names are defined in excel and till this point no vba command is used.
What I want to do is that to write a code which will pick values one by one from range SARbtRng and put these in corresponding cells on sheet2 i.e. It takes value from cell B19 (e.g 10000) and put it in the cell named SA1 (i.e. cell K9) on sheet 2 and then it take value from cell B20 (e.g. 15000) and put it in the cell named SA1 (i.e. cell K10) on sheet 2 and so on...
I am using the following code
Sub B()
For i = 1 To [SARbtRng].Rows.Count
SumAssuredi = "SumAssured" & i
SumAssured = [SARbtRng].Cells(i, 1).Value
Range("SumAssuredi") = SumAssured
Next i
End Sub
This gives the error "Method 'Range' of object '_global' failed.
Please suggest why this error is coming and what code should be used