Problem entering input box data to range after last row VBA

KELLISM

New Member
Joined
Sep 27, 2013
Messages
1
Hi all,

I am looking to add the Date entered via Input Box to the last pasted range without overwriting the data above.

I am new to VBA so my code tends to be trial and error. At present I can copy the data to the column but it is overwriting the original data. I cannot work out how to find the last row of column A and enter the date from the input box adjacent to the data entered in column B. Stopping if column B is empty.

Any help would be greatly appreciated.

Thanks in advance

Here is the code I am currently using

Code:
Sub InputDate()

 Dim strDate As String
 Dim answer As Integer
 
  strDate = InputBox("Insert date in format dd/mm/yy", "User date", Format(Now(), "dd/mm/yy"))
  
  answer = MsgBox("Is the Date Correct? " & strDate, vbYesNo + vbQuestion, "Correct Date")
  
  If answer = vbNo Then
    
 strDate = InputBox("Insert date in format dd/mm/yy", "User date", Format(Now(), "dd/mm/yy"))
 
 Else
 
  
  
  Dim rng As Range
    Dim i As Long


    'Set the range in column B to loop through
     Sheets("Data").Select
  Set rng = Range("B1:B10000")
  
       For Each cell In rng
        'test if cell is empty
        If cell.Value <> "" Then
            'write to adjacent cell
            cell.Offset(1, -1).Value = strDate
        End If
    Next
      
  End If
                    
  
  End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
HTH
Code:
Sub InputDate()
    Dim strDate As String
    Dim answer As Integer
 
    strDate = InputBox("Insert date in format dd/mm/yy", "User date", Format(Now(), "dd/mm/yy"))
    answer = MsgBox("Is the Date Correct? " & strDate, vbYesNo + vbQuestion, "Correct Date")
  
    If answer = vbNo Then
        strDate = InputBox("Insert date in format dd/mm/yy", "User date", Format(Now(), "dd/mm/yy"))
    Else
        Worksheets("Data").Cells(Worksheets("Data").Cells.CurrentRegion.Rows.Count + 1, 2).Value = strDate
    End If
End Sub<
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,334
Members
452,636
Latest member
laura12345

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