Find empty cell after first entry into set of cells containing date

Caveman1964

Board Regular
Joined
Dec 14, 2017
Messages
127
Office Version
  1. 2016
Platform
  1. Windows
Someone had this working but I added more columns that needed dates, now its putting it at end of row.
So I want a macro on page 2 asks for a job number and then searches job number on page 3 in column A.
It finds it then asks for a date. The date will be placed beginning on column W and then every few days they will click that button to update and enter date.
But it will need to be next available cell after W. It will never go past column AF.

Summary;
User clicks button.
Its asks user to enter job number.
It searches page 3 column A:A for job number
if finds the row of that job number.
Moves to column W to enter date.
Then asks user to enter date.
Next time they click button it does same thing but needs to find the empty one after column W which will be X. They enter date and it goes into X.
Appreciate help on this.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Change Sheet3 to suit.

Code:
[COLOR=darkblue]Sub[/COLOR] JobAndDate()
    [COLOR=darkblue]Dim[/COLOR] strJob [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR], strDate [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR], rng As Range
    
    strJob = Application.InputBox("Enter a Job Number.", "Job Number", Type:=2)
    [COLOR=darkblue]If[/COLOR] strJob = "False" [COLOR=darkblue]Then[/COLOR] [COLOR=darkblue]Exit[/COLOR] [COLOR=darkblue]Sub[/COLOR] [COLOR=green]'user canceled[/COLOR]
    
    [COLOR=darkblue]With[/COLOR] Sheets("[COLOR=#ff0000]Sheet3[/COLOR]")
        [COLOR=darkblue]Set[/COLOR] rng = .Range("A:A").Find(strJob, , xlValues, xlWhole, 1, 1, 0)
        
        [COLOR=darkblue]If[/COLOR] [COLOR=darkblue]Not[/COLOR] rng [COLOR=darkblue]Is[/COLOR] [COLOR=darkblue]Nothing[/COLOR] [COLOR=darkblue]Then[/COLOR]
            [COLOR=darkblue]Do[/COLOR]
                DoEvents
                strDate = Application.InputBox("Enter a date.", "Date Entry", Date, Type:=2)
                [COLOR=darkblue]If[/COLOR] strDate = "False" [COLOR=darkblue]Then[/COLOR] [COLOR=darkblue]Exit[/COLOR] [COLOR=darkblue]Sub[/COLOR] [COLOR=green]'user canceled[/COLOR]
                [COLOR=darkblue]If[/COLOR] IsDate(strDate) [COLOR=darkblue]Then[/COLOR] [COLOR=darkblue]Exit[/COLOR] [COLOR=darkblue]Do[/COLOR]
                [COLOR=darkblue]If[/COLOR] MsgBox(strDate & vbLf & vbLf & "Do you want to try again?", _
                          vbExclamation + vbYesNo, "Invadid Date Entry") = vbNo [COLOR=darkblue]Then[/COLOR] [COLOR=darkblue]Exit[/COLOR] [COLOR=darkblue]Sub[/COLOR]
            [COLOR=darkblue]Loop[/COLOR]
            [COLOR=darkblue]If[/COLOR] .Range("W" & rng.Row) = [COLOR=darkblue]Empty[/COLOR] [COLOR=darkblue]Then[/COLOR]
                .Range("W" & rng.Row).Value = DateValue(strDate)
            [COLOR=darkblue]Else[/COLOR]
                .Cells(rng.Row, Columns.Count).End(xlToLeft).Offset(, 1).Value = DateValue(strDate)
            [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
        [COLOR=darkblue]Else[/COLOR]
            MsgBox strJob, vbExclamation, "No Match Found"
        [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]
 
Last edited:
Upvote 0
It works putting into W the first time....but, I need to update with same macro and it move a new date to the next cell, like when I put into W the first time, then 2 days later I want to click and it moves to next cell in row which would be X. So I have column w:af that I want to use for updating. It did put in a new date but it moved it all the way down to end, not the next blank in X.
Thank you for your time. Can you amend the code to do that?
 
Last edited:
Upvote 0
Code:
[color=darkblue]Sub[/color] JobAndDate()
    [color=darkblue]Dim[/color] strJob [color=darkblue]As[/color] [color=darkblue]String[/color], strDate [color=darkblue]As[/color] [color=darkblue]String[/color], rng [color=darkblue]As[/color] Range
    
    strJob = Application.InputBox("Enter a Job Number.", "Job Number", Type:=2)
    [color=darkblue]If[/color] strJob = "False" [color=darkblue]Then[/color] [color=darkblue]Exit[/color] [color=darkblue]Sub[/color] [color=green]'user canceled[/color]
    
    [color=darkblue]With[/color] Sheets("Sheet3")
        [color=darkblue]Set[/color] rng = .Range("A:A").Find(strJob, , xlValues, xlWhole, 1, 1, 0)
        
        [color=darkblue]If[/color] [color=darkblue]Not[/color] rng [color=darkblue]Is[/color] [color=darkblue]Nothing[/color] [color=darkblue]Then[/color]
            [color=darkblue]Do[/color]
                DoEvents
                strDate = Application.InputBox("Enter a date.", "Date Entry", Date, Type:=2)
                [color=darkblue]If[/color] strDate = "False" [color=darkblue]Then[/color] [color=darkblue]Exit[/color] [color=darkblue]Sub[/color] [color=green]'user canceled[/color]
                [color=darkblue]If[/color] IsDate(strDate) [color=darkblue]Then[/color] [color=darkblue]Exit[/color] [color=darkblue]Do[/color]
                [color=darkblue]If[/color] MsgBox(strDate & vbLf & vbLf & "Do you want to try again?", _
                          vbExclamation + vbYesNo, "Invadid Date Entry") = vbNo [color=darkblue]Then[/color] [color=darkblue]Exit[/color] [color=darkblue]Sub[/color]
            [color=darkblue]Loop[/color]
            
            [color=darkblue]If[/color] .Range("AF" & rng.Row) <> [color=darkblue]Empty[/color] [color=darkblue]Then[/color]
                MsgBox "The row is filled with dates for Job# " & strJob, vbExclamation, "Job-Dates Full"
            [color=darkblue]ElseIf[/color] .Range("W" & rng.Row) = [color=darkblue]Empty[/color] [color=darkblue]Then[/color]
                .Range("W" & rng.Row).Value = DateValue(strDate)
            [color=darkblue]Else[/color]
                .Cells(rng.Row, "AG").End(xlToLeft).Offset(, 1).Value = DateValue(strDate)
            [color=darkblue]End[/color] [color=darkblue]If[/color]
        [color=darkblue]Else[/color]
            MsgBox strJob, vbExclamation, "No Match Found"
        [color=darkblue]End[/color] [color=darkblue]If[/color]
    [color=darkblue]End[/color] [color=darkblue]With[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0

Forum statistics

Threads
1,223,901
Messages
6,175,277
Members
452,629
Latest member
SahilPolekar

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