Command button reading a cell

  • Thread starter Thread starter CAM
  • Start date Start date
C

CAM

Hello,

I have a command button that will populate in the worksheet call "Data" in
column A2 and up to 30 or more rows depending upon the workbook "Dept_Sch001
second row will be "Dept_Sch002 and so on.. I like to prevent the user to
press the command button a second time. What I want to have is if column A2
already contains the prefix "Dept_" an error message will appear saying
column A2 already have the prefix "Dept_". and stop. I just want to prevent
the user pressing the command button a second time and not have my coding
populating A2 and so on. Any tips will be appreciated. Thank you in
advance.
 
Why not check for something in A2 right when you start the sub.

If lcase(range("A2").value) like "dept_*" then
MsgBox("A2 already has prefix Dept_" & vbnewline & _
Procedure is ending")
exit sub
end if
 
Option Explicit
sub yoursubhere()

'dim's as required

'a button from the Forms toolbar
if left(lcase(activesheet.range("a2").value), 5) = lcase("Dept_") then
msgbox "already done!"
exit sub
end if

'a commandbutton from the control toolbox toolbar
if left(lcase(Me.range("a2").value), 5) = lcase("Dept_") then
msgbox "already done!"
exit sub
end if

'rest of code

End sub
 
Dave thanks for the needed help.


Dave Peterson said:
Option Explicit
sub yoursubhere()

'dim's as required

'a button from the Forms toolbar
if left(lcase(activesheet.range("a2").value), 5) = lcase("Dept_") then
msgbox "already done!"
exit sub
end if

'a commandbutton from the control toolbox toolbar
if left(lcase(Me.range("a2").value), 5) = lcase("Dept_") then
msgbox "already done!"
exit sub
end if

'rest of code

End sub
 
Back
Top