Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

VBA and EXCEL... HELP Please!

SandySandy Posts: 9Member
Hi everyone,
I am new to VBA although I've been programming in VB for a few years. I am trying to create a time sheet entry program in Excel2000 and have run across a problem I can't get a handle on.
The user enters time into a cell (ex. 4). After entering the 4, I have an export button that they will click to copy the contents of the cell containing the number 4, to another cell in the sheet. No problem so far. The next time they enter time(ex.6), I want the export button to look at the cell containing the 4 and determine whether there is a number already there and if there is, skip down to the next cell and place the 6 there. In other words, I want an if-then-else statement to determine whether a cell is occupied or not. If it is occupied, I want the new time entry to go to a different cell and place its contents there. I am using no variables, I just can't find a function in VBA to use. IsEmpty and IsNull don't seem to work. Here is my code:

If IsEmpty(Worksheets("Monday").Range("j5:k5")) Then
Worksheets("Monday").Range("c11:d11").Copy Destination:=Worksheets("Monday").Range("j5:k5")

ElseIf IsEmpty(Worksheets("Monday").Range("j6:k6")) Then
Worksheets("Monday").Range("c11:d11").Copy Destination:=Worksheets("Monday").Range("j6:k6")

End If

If anyone can help on this I would really appreciate it!
Thanks
Sandy

Comments

  • spindlejspindlej Posts: 70Member
    Try using IsNumeric()=True otherwise, you might have to use = False or = True with IsEmpty.

    For instance

    IsEmpty(Range("A1")) = True

    for a cell that is empty

    IsEmpty(Range("A1")) = false

    for a cell that is not empty.

    Hope this helps.


    : Hi everyone,
    : I am new to VBA although I've been programming in VB for a few years. I am trying to create a time sheet entry program in Excel2000 and have run across a problem I can't get a handle on.
    : The user enters time into a cell (ex. 4). After entering the 4, I have an export button that they will click to copy the contents of the cell containing the number 4, to another cell in the sheet. No problem so far. The next time they enter time(ex.6), I want the export button to look at the cell containing the 4 and determine whether there is a number already there and if there is, skip down to the next cell and place the 6 there. In other words, I want an if-then-else statement to determine whether a cell is occupied or not. If it is occupied, I want the new time entry to go to a different cell and place its contents there. I am using no variables, I just can't find a function in VBA to use. IsEmpty and IsNull don't seem to work. Here is my code:
    :
    : If IsEmpty(Worksheets("Monday").Range("j5:k5")) Then
    : Worksheets("Monday").Range("c11:d11").Copy Destination:=Worksheets("Monday").Range("j5:k5")
    :
    : ElseIf IsEmpty(Worksheets("Monday").Range("j6:k6")) Then
    : Worksheets("Monday").Range("c11:d11").Copy Destination:=Worksheets("Monday").Range("j6:k6")
    :
    : End If
    :
    : If anyone can help on this I would really appreciate it!
    : Thanks
    : Sandy
    :

    [green]SpindleJ[/green]


Sign In or Register to comment.