fixing convert formula to code to autonumber

Hasson

Active Member
Joined
Apr 8, 2021
Messages
390
Office Version
  1. 2016
Platform
  1. Windows
hi

I have this formula to autonumbering in COL B when fill in COL C
VBA Code:
=IF(C4<>"";" serial    " &  SUBTOTAL(3;$C$4:C4);"")
I try doing with this macro but it gives error syntax
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Columns(3)) Is Nothing Then
   LR = Range("c" & Rows.Count).End(xlUp).Row
   Range("b4:b" & LR).Formula = "=IF(C4<>""; "serials" &  SUBTOTAL(3;$C$4:C4);"")"
End If
End Sub
can any one guide me how fix it A or alternative macro
and if doesn't show the formula in column B will be great
thanks for this forum for what provide from the solutions
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hi.​
Rich (BB code):
Range("B4:B" & LR).Formula = "=IF(C4<>"""",""serials""&SUBTOTAL(3,$C$4:C4),"""")"
 
Upvote 0
Double-quotes always present issues for formulas, as they are also used for text qualifiers in VBA.

The easiest way to get the VBA syntax you need is to turn on the Macro Recorder, and record yourself entering the formula in a cell on your worksheet.
Then stop the Macro Recorder, and view the code you just recorded, and you will have the syntax you require.
 
Upvote 0
Or just displaying the native english cell formula in the VBE Immediate window …​
 
Upvote 0
thanks guys for correcting but I have the problem when start from row 4 it begins like this

serial 11

serial 12

serial 13

it should

serial 1

serial 2

and shouldn't show the formula in the column B it should show like value
 
Upvote 0
You can convert all the formulas to hard-coded values in VBA like this:
Rich (BB code):
Range("B4:B" & LR).Formula = "=IF(C4<>"""",""serials""&SUBTOTAL(3,$C$4:C4),"""")"
Range("B4:B" & LR).Value = Range("B4:B" & LR).Value
 
Upvote 0
Solution
You are welcome.
Glad we could help.
 
Upvote 0

Forum statistics

Threads
1,215,578
Messages
6,125,642
Members
449,245
Latest member
PatrickL

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