Error when I delete content in multiple cells simultaneously

Navina Gawade

New Member
Joined
May 15, 2023
Messages
4
Office Version
  1. 2019
Platform
  1. Windows
As I'm new to VBA I have tried following code which is working perfectly unless and until I delete some content in multiple cells of column B simultaneously.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 2 Then
If Target.Value = "Shares" Then
Target.Offset(0, 1).Value = "Equity"
End If
End If
End Sub
(I used this code so that whenever I'll enter Shares in column B automatically equity will be popup in column C and whenever I'll type something other than shares column C will remain as it is. )

IMG-20230609-WA0009.jpg
IMG-20230609-WA0008.jpg
Can someone help me with code which will not result in such error as I'm totally unaware of VBA working.
 

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.
Welcome to the Board!

See if this fixes your issue:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.CountLarge > 1 Then Exit Sub
   
    If (Target.Column = 2) And (Target.Value = "Shares") Then
        Target.Offset(0, 1).Value = "Equity"
    End If

End Sub
 
Upvote 1
Solution
Welcome to the Board!

See if this fixes your issue:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.CountLarge > 1 Then Exit Sub
  
    If (Target.Column = 2) And (Target.Value = "Shares") Then
        Target.Offset(0, 1).Value = "Equity"
    End If

End Sub
Yes it's working now.
Thank you so much for this.
 
Upvote 0
Hi
Try
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Not Intersect(Target.Columns, Columns(2)) Is Nothing Then
        If Target.Value = "Shares" Then
            Target.Offset(0, 1).Value = "Equity"
        End If
    End If
End Sub
 
Upvote 0
But now it's giving me same error whenever I delete content in other than column B.
Can you give me an example of exactly what you are doing?
Are you deleting whole rows or columns?
If so, which ones?
 
Upvote 0
Can you give me an example of exactly what you are doing?
Are you deleting whole rows or columns?
If so, which ones?
I was actually using "2" instead of "1" in IF target.countlarge>1 as I shifted date from b column to C column and C column to D column. But now I used "1" and it's not giving me error now. Thank you so much for help.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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