S
StargateFanFromWork
After all these years I've been trying to get a handle on those IF THEN (and
ELSE) statements. For some reason, my brain has never grasped how do use
these. Intellectually I understand, and have always understood, I just
don't seem to get working code. There seems to be some sort of block for
getting effective, working code. I've fiddled yet again today for a long
time without getting this to work. I've looked at many examples in archives
but no luck.
Here is what my macro looks like now:
*********************************************************
Sub AddNewEntry()
'
ActiveSheet.Unprotect 'place at the beginning of the code
If Range("A2") <> "" Then
Application.Goto Reference:="R1C3"
Range("A2").Select
Else
Application.Goto Reference:="R1C3"
Range("A2").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
End If
ActiveSheet.Protect ' place at end of code
End Sub
*********************************************************
I'm trying to do this:
If (condition) Then
' do something
Else
' do something else
End If
but in testing the code, it isn't working properly. On both sheets this is
used on, the behaviour is exactly the same even though the conditions are
not the same and I should have different results.
So, if there is only a header in column A, only this is needed:
Application.Goto Reference:="R1C3"
Range("A2").Select
If there are more than 2 rows of data, then this will happen:
Application.Goto Reference:="R1C3"
Range("A2").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
Thanks in advance for any help. If I can just lick this, I know that I will
really have broken the barrier and will be able to do quite a bit more in
XL2K.
D
ELSE) statements. For some reason, my brain has never grasped how do use
these. Intellectually I understand, and have always understood, I just
don't seem to get working code. There seems to be some sort of block for
getting effective, working code. I've fiddled yet again today for a long
time without getting this to work. I've looked at many examples in archives
but no luck.
Here is what my macro looks like now:
*********************************************************
Sub AddNewEntry()
'
ActiveSheet.Unprotect 'place at the beginning of the code
If Range("A2") <> "" Then
Application.Goto Reference:="R1C3"
Range("A2").Select
Else
Application.Goto Reference:="R1C3"
Range("A2").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
End If
ActiveSheet.Protect ' place at end of code
End Sub
*********************************************************
I'm trying to do this:
If (condition) Then
' do something
Else
' do something else
End If
but in testing the code, it isn't working properly. On both sheets this is
used on, the behaviour is exactly the same even though the conditions are
not the same and I should have different results.
So, if there is only a header in column A, only this is needed:
Application.Goto Reference:="R1C3"
Range("A2").Select
If there are more than 2 rows of data, then this will happen:
Application.Goto Reference:="R1C3"
Range("A2").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
Thanks in advance for any help. If I can just lick this, I know that I will
really have broken the barrier and will be able to do quite a bit more in
XL2K.
