RAJESH1960
Banned for repeated rules violations
- Joined
- Mar 26, 2020
- Messages
- 2,313
- Office Version
- 2019
- Platform
- Windows
Hello guys
When I run the first half of the code separately it is running fine but when I add the second half where I have to replace “(as per details”) with the cell reference I am not able to get the result. I am getting a compile error. Can someone please see what is wrong with the code.?
Sub VoucherNos()
Dim VchNo As Integer
Dim CELL As Variant
VchNo = 1000
For Each CELL In Range("D2:D" & Range("C" & Rows.Count).End(xlUp).Row)
If Not CELL = vbNullString Then
VchNo = VchNo + 1
CELL.Value = VchNo
End If
Next
Dim NewName As String
NewName = Sheets("Original").Range("K1")
If CELL.Offset(0, -4) = "(as per details)" Then CELL.Offset(0, -4).Value = NewName
End With
End Sub
When I run the first half of the code separately it is running fine but when I add the second half where I have to replace “(as per details”) with the cell reference I am not able to get the result. I am getting a compile error. Can someone please see what is wrong with the code.?
Sub VoucherNos()
Dim VchNo As Integer
Dim CELL As Variant
VchNo = 1000
For Each CELL In Range("D2:D" & Range("C" & Rows.Count).End(xlUp).Row)
If Not CELL = vbNullString Then
VchNo = VchNo + 1
CELL.Value = VchNo
End If
Next
Dim NewName As String
NewName = Sheets("Original").Range("K1")
If CELL.Offset(0, -4) = "(as per details)" Then CELL.Offset(0, -4).Value = NewName
End With
End Sub
Book1 | |||||||||
---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | |||
1 | Line | Date | Vch Type | Vch No. | Particulars | Debit | Credit | ||
2 | 17 | 02-07-2021 | Receipt | 3 | Sunday | 1015.00 | |||
3 | 30 | 04-07-2021 | Payment | 6 | January | 100.00 | |||
4 | 36 | 06-07-2021 | Contra | 1 | Cash | 1000.00 | |||
5 | 37 | 06-07-2021 | Contra | 2 | Cash | 2000.00 | |||
6 | 44 | 11-07-2021 | Receipt | 11 | Sunday | 1015.00 | |||
7 | 45 | 11-07-2021 | Payment | 10 | January | 100.00 | |||
8 | 46 | 12-07-2021 | Receipt | 12 | Sunday | 1015.00 | |||
9 | 47 | 12-07-2021 | Payment | 11 | January | 100.00 | |||
10 | 48 | 14-07-2021 | Contra | 3 | Cash | 2000.00 | |||
11 | 49 | 14-07-2021 | Contra | 4 | Cash | 1000.00 | |||
12 | |||||||||
13 | 1 | 01-07-2021 | Receipt | 1 | (as per details) | 4040.00 | |||
14 | 2 | Sunday | 1015.00 | ||||||
15 | 3 | Monday | 2025.00 | ||||||
16 | 4 | Tuesday | 1000.50 | ||||||
17 | 5 | Round Off | 0.50 | ||||||
18 | 6 | 01-07-2021 | Payment | 1 | (as per details) | 1001.00 | |||
19 | 7 | January | 100.00 | ||||||
20 | 8 | February | 200.00 | ||||||
21 | 9 | March | 300.00 | ||||||
22 | 10 | April | 400.00 | ||||||
23 | 11 | Round Off | 1.00 | ||||||
24 | 12 | 02-07-2021 | Receipt | 2 | (as per details) | 4040.00 | |||
25 | 13 | Sunday | 1015.00 | ||||||
26 | 14 | Monday | 2025.00 | ||||||
27 | 15 | Tuesday | 1000.50 | ||||||
28 | 16 | Round Off | 0.50 | ||||||
29 | 18 | 03-07-2021 | Payment | 2 | (as per details) | 1001.00 | |||
30 | 19 | January | 100.00 | ||||||
31 | 20 | February | 200.00 | ||||||
32 | 21 | March | 300.00 | ||||||
33 | 22 | April | 400.00 | ||||||
34 | 23 | Round Off | 1.00 | ||||||
35 | 24 | 04-07-2021 | Payment | 3 | (as per details) | 1001.00 | |||
36 | 25 | January | 100.00 | ||||||
37 | 26 | February | 200.00 | ||||||
38 | 27 | March | 300.00 | ||||||
39 | 28 | April | 400.00 | ||||||
40 | 29 | Round Off | 1.00 | ||||||
41 | 31 | 05-07-2021 | Receipt | 4 | (as per details) | 4040.00 | |||
42 | 32 | Sunday | 1015.00 | ||||||
43 | 33 | Monday | 2025.00 | ||||||
44 | 34 | Tuesday | 1000.50 | ||||||
45 | 35 | Round Off | 0.50 | ||||||
46 | 38 | 09-07-2021 | Payment | 9 | (as per details) | 1001.00 | |||
47 | 39 | January | 100.00 | ||||||
48 | 40 | February | 200.00 | ||||||
49 | 41 | March | 300.00 | ||||||
50 | 42 | April | 400.00 | ||||||
51 | 43 | Round Off | 1.00 | ||||||
Bank |