VBA Questions For Auto filling Cells

data808

Active Member
Joined
Dec 3, 2010
Messages
353
Office Version
  1. 2019
Platform
  1. Windows
I am using this and it works fine:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    With Target
        If .Count > 1 Then Exit Sub
        If Not Intersect(Range("E:E"), .Cells) Is Nothing Then
        Application.EnableEvents = False
        With Range("K" & Target.Row)
                ActiveSheet.Unprotect Password:="hello"
                .Value = "TEST"
        With Range("I" & Target.Row)
                .Value = "Stuff"
                ActiveSheet.Protect Password:="hello"
        End With
        End With
        Application.EnableEvents = True
        End If
    End With
End Sub

But now I want to add some if statements to make the user have to type in specific codes for it to trigger. Right now as long as they type anything into column E, it will trigger column I and K to auto-fill "TEST" and "Stuff".

How would I change this VBA so that if the user types "1234" into column E for example, only then will it trigger to auto-fill column I and K?

I would also like it if the user types anything other than "1234" or deletes it to leave column E blank, then columns I and K, for that row, will go back to being null or blank.

Thank you for your help on this.
 
Unless I have misunderstood what you are saying, there should be no issue at all with a structure like that. Here it is working ..

data808.xlsm
AB
4
5
6abc 123
7
8
Sheet1


data808.xlsm
AB
12
13
14abc 123
15
16
Sheet2
Cell Formulas
RangeFormula
A14A14=Sheet1!A6
Yeah it's odd. It works for me too if I just do it from a blank spreadsheet but once I try it on the one we been working on, it doesn't work. I notice that when I add this =Sheet1!A6 to the cell, that formula does not disappear from the cell. It will register as if it were a value so that tells me it's not recognizing it as a formula but rather a value.
 
Upvote 0

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Unless I have misunderstood what you are saying, there should be no issue at all with a structure like that. Here it is working ..

data808.xlsm
AB
4
5
6abc 123
7
8
Sheet1


data808.xlsm
AB
12
13
14abc 123
15
16
Sheet2
Cell Formulas
RangeFormula
A14A14=Sheet1!A6
So it appears to not allow any type of formulas on this sheet. Every type of formula that I type into any of the cells on this sheet will only show the formula in the cell itself but not function at all. If I create a new blank sheet in this workbook it works fine. But if I copy one of the cells from the non-working sheet and paste it into one of the blank sheets, that cell will become unusable to any formulas. Is there any setting in the ribbon that would cause this? I may have touched something to cause all formulas to not function on this sheet.
 
Upvote 0
Unless I have misunderstood what you are saying, there should be no issue at all with a structure like that. Here it is working ..

data808.xlsm
AB
4
5
6abc 123
7
8
Sheet1


data808.xlsm
AB
12
13
14abc 123
15
16
Sheet2
Cell Formulas
RangeFormula
A14A14=Sheet1!A6
I found it. It's because I formatted the cells to Text instead of General. When in General format, the formula works.
 
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,970
Members
449,095
Latest member
Mr Hughes

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