Modify the VBA Code

PAPPU

New Member
Joined
Jan 28, 2022
Messages
20
Office Version
  1. 365
Platform
  1. Windows
Hi Experts,

I am using the following code in Sheet1

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Intersect(Target, Columns("B")) Is Nothing Then Exit Sub

Set Target = Target.Cells(1)

Application.EnableEvents = False
If Target = "" Then
    Target.Offset(, 5) = ""
End If
Application.EnableEvents = True
End Sub

I have Sheet 1 and Sheet 2.
In Sheet 1, the values in B2:D2 are populated from Sheet2. The values in E2:F2 are with formula based on entries in B2:D2. And in G2: I2 I have drop down entries using data validation( which I will insert manually).
Sheet 1a.JPG

Now as per the code , in Sheet 2 : If I revert the entry from Alphabet to Number in Sheet 2 , it will remove the entries from B2: F2 and keep it as blank cells in Sheet 1. When it happens I want G2:I2 entries to go blank as well, but still ready for re-entry. The code works perfectly when it happens with the last Row entry in sheet 1- Row 4. It removes all entries from G4:I4 as blank , still with dropdown feature

But if I change the reversion in Sheet 2 (Alphabet to Number), say it belongs to Row 2 in Sheet1, it shows as below
Sheet 1b.JPG

It works here, as it intended for Row 2, But when such type of action happens between the rows, due to other Code set up in sheet 2, the respective cells from Column B to Column F is being shifted up without disturbing the SL NO column (stays constant as intended). It shows the table view like above, though it removes the entry from Row 2, it removes dropdown entry from one row below Cells from G-H-I column and keeping the last row unchanged.
I want it to be aligned each other from left to right cells and if I revert any change in Sheet 2 , which belongs to any middle row in sheet 1, then the respective cells only needed as blank, and the bottom cells to be realigned again with respective row entries.

Any thoughts-solution , will be grateful
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Forum statistics

Threads
1,215,731
Messages
6,126,537
Members
449,316
Latest member
sravya

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