Use a Cell to check value of a different cell to populate another cell

User avatar
DocAElstein
4StarLounger
Posts: 584
Joined: 18 Jan 2022, 15:59
Location: Re-routing rivers, in Hof, Beautiful Bavaria

Re: Use a Cell to check value of a different cell to populate another cell

Post by DocAElstein »

bradjedis wrote:
19 Jan 2023, 00:32
….added this to the VBA and it does what I need...
If Rng.Offset(0, 0).Value = "" Then Let Rng.Offset(0, 2).Value = ""
Strange, but Interesting: It sounds like you are saying you are getting different results from these 2 logics:
_1) Alan’s first coding, (you claim that does not work for you):
Let Rng.Offset(0, 2).Value = ""
If Rng.Offset(0, 0).Value <> "" Then Let Rng.Offset(0, 2).Value = 1


_2) bradjedis’s latest possibly working…(appears initially to …. does what I need...)
If Rng.Offset(0, 0).Value <> "" Then Let Rng.Offset(0, 2).Value = 1
If Rng.Offset(0, 0).Value = "" Then Let Rng.Offset(0, 2).Value = ""



I can’t initially think why that should be, but I may have missed something or am just slow at getting the point again.
_.____________________________________________________________________
bradjedis wrote:
19 Jan 2023, 00:32
Will continue testing...
Remember wot I said about saving , closing and reopening after any changes before you do any testing. It may not appear to be necessary but it has been sometimes in the past, and occasionally helped to prevent some nasty crashes. If you forget to do that you might be mislead and end up going around in circles chasing your tail.
Remember also, as I said a few times, this is an interesting academic excessive for me. I would not necessarily recommend using this sort of thing, at least not without knowing the whole history of you and what all this is all about / for. As I said before. use at your risk.
( I use it. One reason: I sometimes learn the best, and get the most out of, fixing things when I occasionally unintentionally break them. )

_._____________________________________________________________________

Event coding method alternative....
DocAElstein wrote:
15 Jan 2023, 09:22
. A more conventional way using Event coding might be safer.
Here a simple example:

Code: Select all

 Option Explicit  '
Private Sub Worksheet_Change(ByVal Target As Range) ' https://eileenslounge.com/viewtopic.php?p=303288#p303288
    If Target.Cells.Count <> 1 Or Target.Column <> 5 Then Exit Sub ' I am only intersted in a cell change in column E
    If Target.Offset(0, 0).Value <> "" Then Let Target.Offset(0, 2).Value = 1
    If Target.Offset(0, 0).Value = "" Then Let Target.Offset(0, 2).Value = ""
End Sub 
( Something like that needs to go in the worksheet object code module: One way to get to that is right click on the tab and select an option like View Code https://i.postimg.cc/rmD0qSMq/Right-Cli ... w-Code.jpg )

CodeInFirstWorksheetObjectCodeModule.xls https://app.box.com/s/a7k2izgyzqhd7f98hlaq9csw0l4tyyl6
_._______________________________________________________________________

rory wrote:
18 Jan 2023, 23:34
Trying to audit/maintain workbooks with this kind of function in them can be an absolute nightmare.
Perhaps some more lateral thinking might help to solve that problem. Give auditors, maintainers, updaters something else to do instead. On average they cause as many problems as they solve, prevent, or repair, IMO. More emphasis should be put on the individual getting it right and knowing what he is doing in the first place, IMO. That is not a perfect solution either. There will be mistakes and problem later, maybe big ones, yes. But no more than all the controllers, auditor’s, maintainers, updater’s cause themselves: But giving the auditors and controllers a snow shovel and getting them to clear away the snow, (or insulate my pipes after I repaired them again), for me instead, would be a more efficient use of them , IMO. :snow: ( I can’t set them on my little train diverting project as I expect they wouldn’t have the bottle, moral inclination, or ability to do anything useful there without messing it up at some stage.)

_.____________________
rory wrote:
18 Jan 2023, 23:34
...this sort of behaviour is not allowed ....
I am not quite sure what you mean by that? As far as I am concerned he has my permission to use it. I hereby confirm that he may use it if he so chooses to!
Alan
You do not have the required permissions to view the files attached to this post.
Last edited by DocAElstein on 24 Jan 2023, 06:32, edited 4 times in total.
I seriously don’t ever try to annoy. Maybe I am just the kid that missed being told about the King’s new magic suit, :(

User avatar
SpeakEasy
4StarLounger
Posts: 550
Joined: 27 Jun 2021, 10:46

Re: Use a Cell to check value of a different cell to populate another cell

Post by SpeakEasy »

I'm with HansV - no need for some sort of complicated proxie function (unless there are some other constraints that you have not mentioned). Just stick his formula into G5 itself

bradjedis
4StarLounger
Posts: 538
Joined: 30 Mar 2010, 18:49
Location: United States

Re: Use a Cell to check value of a different cell to populate another cell

Post by bradjedis »

Ok,

I will play around with the Formula =IF(E5="", "", 1) and see if everything works..


Will reply tomorrow.

Brad

bradjedis
4StarLounger
Posts: 538
Joined: 30 Mar 2010, 18:49
Location: United States

Re: Use a Cell to check value of a different cell to populate another cell

Post by bradjedis »

After testing, The Formula =IF(E5="", "", 1) suits my needs. The other method explored within this posting does work as well.



Thanks to all

User avatar
DocAElstein
4StarLounger
Posts: 584
Joined: 18 Jan 2022, 15:59
Location: Re-routing rivers, in Hof, Beautiful Bavaria

Re: Use a Cell to check value of a different cell to populate another cell

Post by DocAElstein »

Great, good news! Thx for the feedback.

( Did you try the Event coding method as well ( a few posts up - https://eileenslounge.com/viewtopic.php ... 8&start=20 ) )?
Image

CodeInFirstWorksheetObjectCodeModule.xls https://app.box.com/s/a7k2izgyzqhd7f98hlaq9csw0l4tyyl6
I seriously don’t ever try to annoy. Maybe I am just the kid that missed being told about the King’s new magic suit, :(