Macro Not Working

  • Thread starter Thread starter robertguy
  • Start date Start date
R

robertguy

Hi can any please advise me why my Macro is not working

The Macro allows users to Input dates via a message box which shoul
then be input in cells B1, B2, B3 & B4 - but this does not happen - I
addition when I try to change the sheet name in the macro from Sheet2 t
another name i.e. mydata it displays an error



Sub Input_Dates1()
'
'
MyName = InputBox("Please Enter Date for Q1")
If MyName = "" Then
Exit Sub
End If
Sheet2.Range("$B$1").Value = MyName

MyName = InputBox("Please Enter Date for Q2")
If MyName = "" Then
Exit Sub
End If
Sheet2.Range("$B$2").Value = MyName

MyName = InputBox("Please Enter Date for Q3")
If MyName = "" Then
Exit Sub
End If
Sheet2.Range("$B$3").Value = MyName

MyName = InputBox("Please Enter Date for Q3")
If MyName = "" Then
Exit Sub
End If
Sheet2.Range("$B$4").Value = MyName


End Sub



Any help would be appreciated


Excel version 2000



Many thanks



Ro
 
hi,
try this
Dim myname As Date

myname = InputBox("Please Enter Date for Q1")
If IsNull(myname) Then
Exit Sub
End If
Sheet2.Range("$B$1").Value = myname

but if they don't input a date there will be a type
mismatch error.
 
when you say it is not working, what is the error you are getting?

the only thing that i can see is that you have not defined a variabl
'myname'
 
It works OK for me, do you have in a standard module? Theres nothing wrong
with the code but
Sheet2 is Sheet2 regardless of what you may rename it,
If you use Sheets("MyData") it will respond to the name you have given the
sheet,
Regards,
 
If you use the code you pasted you should either change the sheet name
in the code to match the sheet name in your workbook, or change your
sheet name in your workbook to "Sheet2" - the sheet names must match or
it will not work.
 
Sorry but that's not quite right, if you use Sheet2.Range("A1") as opposed
to Sheets("Sheet2").Range("A1") then Sheet2 remains as Sheet2 regardless of
what you rename it. In the VB Editor one can see Sheet2 (Sheet2) which is
how VB sees Sheet2, the Sheet2 in brackets is what you choose to rename it,
Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

F.A.O Mike H 3
Debug Error 7
Link 3
Use Named Range instead? 25
Compile error 2
macro problem 1
macro listing subfolders from selection of mainfolders 1
VBA CreateNames (ignores last 5 rows?) 6

Back
Top