macro is working and getting run time error

Prasad K

Board Regular
Joined
Aug 4, 2021
Messages
189
Office Version
  1. 2016
  2. 2007
Platform
  1. Windows
i have applied macro for insert serial no if isblank cell and i know we can apply this formula also why i have applied a macro for insert serial no if isblank cell
because i want to insert serial no automatic with appling the macro that's why i have created a macro for this and here a problem i have getting run time error

here i want when the macro applied serial no the formula should be hidden


VBA Code:
Sub SerialNo()
  Dim LastRow As Long
  LastRow = Cells(Rows.Count, "B").End(xlUp).Row
  Range("A1:A" & LastRow).FormulaR1C1 = "=IF(ISBLANK(RC[1]),"""",COUNTA(R1C2:RC[1]))"
  Rng.Value = Rng.Value
End Sub
 

Attachments

  • O1.PNG
    O1.PNG
    9.8 KB · Views: 9
  • O2.PNG
    O2.PNG
    6.3 KB · Views: 9

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
You have not defined what "rng" is. You can avoid that sort of thing happening to you by ensuring you use 'Option Explicit' at the top of every module. That is easy with this setting in the vba module

1631869464118.png


You could also try this for the current issue.

VBA Code:
Sub SerialNo()
  Dim LastRow As Long
  LastRow = Cells(Rows.Count, "B").End(xlUp).Row
  With Range("A1:A" & LastRow)
    .FormulaR1C1 = "=IF(ISBLANK(RC[1]),"""",COUNTA(R1C2:RC[1]))"
    .Value = .Value
  End With
End Sub
 
Upvote 0
Solution
You have not defined what "rng" is. You can avoid that sort of thing happening to you by ensuring you use 'Option Explicit' at the top of every module. That is easy with this setting in the vba module

View attachment 47129

You could also try this for the current issue.

VBA Code:
Sub SerialNo()
  Dim LastRow As Long
  LastRow = Cells(Rows.Count, "B").End(xlUp).Row
  With Range("A1:A" & LastRow)
    .FormulaR1C1 = "=IF(ISBLANK(RC[1]),"""",COUNTA(R1C2:RC[1]))"
    .Value = .Value
  End With
End Sub
Thank you Peter
RunTime Problem has been solved
 
Upvote 0
You're welcome. Thanks for the follow-up. :)

(I hope you made the vba editor change that I suggested too. ;))
 
Upvote 0

Forum statistics

Threads
1,214,915
Messages
6,122,212
Members
449,074
Latest member
cancansova

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