Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Setting a cell equal to a variable in excel - vba?

I get the error message Object Required

Here is an edited version of the code to only include my error section:

Public Sub CommandButton1_Click()

Application.EnableCancelKey = xlDisabled

Dim First_Name As String

While First_Name = "Enter First Name Here. Ex. John" Or First_Name = ""

First_Name = Application.InputBox("Enter New Employee First Name.", "First Name", "Enter First Name Here. Ex. John")

Sheets("Sheet2").Range("A1").Select

Do Until IsEmpty(ActiveCell)

ActiveCell.Offset(1, 0).Select

Loop

Target.Value = First_Name

Wend

End Sub

At the line: target.value = First_Name

I get runtime 434 --> "object required"

What is wrong with the code?

Verbal summary of what I want the code to do:

Have user enter name into Input box.

Take that name and place it into the next empty cell on "Sheet2", Column "A"

I'm in the beginner stages of learning VBA. I am open to any suggestions or criticisms of my code

I left out many other input boxes, error checks, and password to begin script as i felt it irrelevant.

Update:

EDIT:

I think my problem is that I want to edit cells on a different page than my button.

Update 2:

:Reported Abuse on Ronaldin. Advertisement.

2 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    This should be all you need to accomplish your goal. You can copy and paste this macro as is:

    Public Sub CommandButton1_Click()

    Application.EnableCancelKey = xlDisabled

    Dim First_Name As String

    First_Name = Application.InputBox _

    ("Enter New Employee First Name.", _

    "First Name", "Enter First Name Here. Ex. John")

    Sheets("Sheet2").Range("A" & ActiveSheet.Rows.Count). _

    End(xlUp).Offset(1, 0).Value = First_Name

    End Sub

  • 4 years ago

    1

    Source(s): PhoneLookup Directories http://reversephonenumberlookup.enle.info/?3921
Still have questions? Get your answers by asking now.