Code to replace selected data with reference from different sheet

Status
Not open for further replies.

RAJESH1960

Banned for repeated rules violations
Joined
Mar 26, 2020
Messages
2,313
Office Version
  1. 2019
Platform
  1. 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
Book1
ABCDEFG
1LineDateVch TypeVch No.ParticularsDebitCredit
21702-07-2021Receipt3Sunday1015.00
33004-07-2021Payment6January100.00
43606-07-2021Contra1Cash1000.00
53706-07-2021Contra2Cash2000.00
64411-07-2021Receipt11Sunday1015.00
74511-07-2021Payment10January100.00
84612-07-2021Receipt12Sunday1015.00
94712-07-2021Payment11January100.00
104814-07-2021Contra3Cash2000.00
114914-07-2021Contra4Cash1000.00
12
13101-07-2021Receipt1(as per details)4040.00
142Sunday1015.00
153Monday2025.00
164Tuesday1000.50
175Round Off0.50
18601-07-2021Payment1(as per details)1001.00
197January100.00
208February200.00
219March300.00
2210April400.00
2311Round Off1.00
241202-07-2021Receipt2(as per details)4040.00
2513Sunday1015.00
2614Monday2025.00
2715Tuesday1000.50
2816Round Off0.50
291803-07-2021Payment2(as per details)1001.00
3019January100.00
3120February200.00
3221March300.00
3322April400.00
3423Round Off1.00
352404-07-2021Payment3(as per details)1001.00
3625January100.00
3726February200.00
3827March300.00
3928April400.00
4029Round Off1.00
413105-07-2021Receipt4(as per details)4040.00
4232Sunday1015.00
4333Monday2025.00
4434Tuesday1000.50
4535Round Off0.50
463809-07-2021Payment9(as per details)1001.00
4739January100.00
4840February200.00
4941March300.00
5042April400.00
5143Round Off1.00
Bank
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Status
Not open for further replies.

Forum statistics

Threads
1,214,832
Messages
6,121,845
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top