Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Input Box only if a cell is blank

Hi, I'm a VBA noob. At most I glean from the genius on this forum and copy
and paste your functions into my workbooks. I took a modified version of
this code directly from this forum, but I don't know how to change it so that
the input box will only pop up if the cell is blank.

Option Explicit
Private Sub Workbook_Open()

Dim ClientName As String

ClientName = InputBox("Please input the Client's Name")

Worksheets("Summary").Range("A4") = ClientName

End Sub

Also I only need the input box to pop up if the user is on the tab titled
"Summary," not as the book is opened.

Any help is greatly appreciated!

Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default Input Box only if a cell is blank

hi
if statemate......
Option Explicit
Private Sub Workbook_Open()
If WorkSheets("Summary").Range("A4").value = "" then
Dim ClientName As String
ClientName = InputBox("Please input the Client's Name")
Worksheets("Summary").Range("A4").value = ClientName
end if
End Sub

regards
FSt1

"Audrey" wrote:

Hi, I'm a VBA noob. At most I glean from the genius on this forum and copy
and paste your functions into my workbooks. I took a modified version of
this code directly from this forum, but I don't know how to change it so that
the input box will only pop up if the cell is blank.

Option Explicit
Private Sub Workbook_Open()

Dim ClientName As String

ClientName = InputBox("Please input the Client's Name")

Worksheets("Summary").Range("A4") = ClientName

End Sub

Also I only need the input box to pop up if the user is on the tab titled
"Summary," not as the book is opened.

Any help is greatly appreciated!

Thanks!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Input Box only if a cell is blank

You need to capture 2 events. If the sheet is opened on the summary tab then
you want to add the client name... The other is if you select the summary
tab... If it were me I would write a sub to add the name (if appropriate) and
then just call it from the on open event and from the sheet activate event...
Something like this...

Option Explicit

Private Sub Workbook_Open()
Call AddClient(ActiveSheet)
End Sub

Private Sub Workbook_SheetActivate(ByVal sh As Object)
Call AddClient(sh)
End Sub

Private Sub AddClient(ByVal sh As Worksheet)
With sh
If .Name = "Summary" Then
If Trim(.Range("A4").Value) = "" Then
.Range("A4").Value = InputBox("Please input the Client's Name")
End If
End If
End With
End Sub
--
HTH...

Jim Thomlinson


"Audrey" wrote:

Hi, I'm a VBA noob. At most I glean from the genius on this forum and copy
and paste your functions into my workbooks. I took a modified version of
this code directly from this forum, but I don't know how to change it so that
the input box will only pop up if the cell is blank.

Option Explicit
Private Sub Workbook_Open()

Dim ClientName As String

ClientName = InputBox("Please input the Client's Name")

Worksheets("Summary").Range("A4") = ClientName

End Sub

Also I only need the input box to pop up if the user is on the tab titled
"Summary," not as the book is opened.

Any help is greatly appreciated!

Thanks!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Input Box only if a cell is blank

Delete the existing code from Thisworkbook module.

Go to "Summary" sheet and right-click on the sheet tab.

Copy/paste this code into that sheet module. Will run when the sheet is
activated/selected.

If A4 is blank the InputBox will appear. Otherwise.....nothing.

Private Sub Worksheet_Activate()
Dim ClientName As String
If Me.Range("A4") = "" Then
ClientName = InputBox("Please input the Client's Name")
Me.Range("A4") = ClientName
End If
End Sub


Gord Dibben MS Excel MVP

On Tue, 11 Dec 2007 16:57:02 -0800, Audrey
wrote:

Hi, I'm a VBA noob. At most I glean from the genius on this forum and copy
and paste your functions into my workbooks. I took a modified version of
this code directly from this forum, but I don't know how to change it so that
the input box will only pop up if the cell is blank.

Option Explicit
Private Sub Workbook_Open()

Dim ClientName As String

ClientName = InputBox("Please input the Client's Name")

Worksheets("Summary").Range("A4") = ClientName

End Sub

Also I only need the input box to pop up if the user is on the tab titled
"Summary," not as the book is opened.

Any help is greatly appreciated!

Thanks!


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Input Box only if a cell is blank

What if the book opens with the summary sheet as the active sheet?
--
HTH...

Jim Thomlinson


"Gord Dibben" wrote:

Delete the existing code from Thisworkbook module.

Go to "Summary" sheet and right-click on the sheet tab.

Copy/paste this code into that sheet module. Will run when the sheet is
activated/selected.

If A4 is blank the InputBox will appear. Otherwise.....nothing.

Private Sub Worksheet_Activate()
Dim ClientName As String
If Me.Range("A4") = "" Then
ClientName = InputBox("Please input the Client's Name")
Me.Range("A4") = ClientName
End If
End Sub


Gord Dibben MS Excel MVP

On Tue, 11 Dec 2007 16:57:02 -0800, Audrey
wrote:

Hi, I'm a VBA noob. At most I glean from the genius on this forum and copy
and paste your functions into my workbooks. I took a modified version of
this code directly from this forum, but I don't know how to change it so that
the input box will only pop up if the cell is blank.

Option Explicit
Private Sub Workbook_Open()

Dim ClientName As String

ClientName = InputBox("Please input the Client's Name")

Worksheets("Summary").Range("A4") = ClientName

End Sub

Also I only need the input box to pop up if the user is on the tab titled
"Summary," not as the book is opened.

Any help is greatly appreciated!

Thanks!





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Input Box only if a cell is blank

Option Explicit
Private Sub Workbook_Open()

Dim ClientName As String
Dim myCell as range

set myCell = me.worksheets("summary").range("a4")

if trim(mycell.value) = "" then
ClientName = InputBox("Please input the Client's Name")
mycell.value = ClientName
end if

End Sub

Audrey wrote:

Hi, I'm a VBA noob. At most I glean from the genius on this forum and copy
and paste your functions into my workbooks. I took a modified version of
this code directly from this forum, but I don't know how to change it so that
the input box will only pop up if the cell is blank.

Option Explicit
Private Sub Workbook_Open()

Dim ClientName As String

ClientName = InputBox("Please input the Client's Name")

Worksheets("Summary").Range("A4") = ClientName

End Sub

Also I only need the input box to pop up if the user is on the tab titled
"Summary," not as the book is opened.

Any help is greatly appreciated!

Thanks!


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Input Box only if a cell is blank

I'm not sure why it would make a difference what sheet is visible when it's
opened, but you could do something like:

Option Explicit
Private Sub Workbook_Open()

Dim ClientName As String
Dim myCell as range

set myCell = me.worksheets("summary").range("a4")

if trim(mycell.value) = "" then
application.goto mycell, scroll:=true
ClientName = InputBox("Please input the Client's Name")
mycell.value = ClientName
end if

End Sub

I missed the last part of your question.

Dave Peterson wrote:

Option Explicit
Private Sub Workbook_Open()

Dim ClientName As String
Dim myCell as range

set myCell = me.worksheets("summary").range("a4")

if trim(mycell.value) = "" then
ClientName = InputBox("Please input the Client's Name")
mycell.value = ClientName
end if

End Sub

Audrey wrote:

Hi, I'm a VBA noob. At most I glean from the genius on this forum and copy
and paste your functions into my workbooks. I took a modified version of
this code directly from this forum, but I don't know how to change it so that
the input box will only pop up if the cell is blank.

Option Explicit
Private Sub Workbook_Open()

Dim ClientName As String

ClientName = InputBox("Please input the Client's Name")

Worksheets("Summary").Range("A4") = ClientName

End Sub

Also I only need the input box to pop up if the user is on the tab titled
"Summary," not as the book is opened.

Any help is greatly appreciated!

Thanks!


--

Dave Peterson


--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Input Box only if a cell is blank

Jim, this is fantastic! It's working exactly how I need it to.

Jim, Dave, Gord, FSt1, thank you all so much for your help! I really
appreciate it!!

"Jim Thomlinson" wrote:

You need to capture 2 events. If the sheet is opened on the summary tab then
you want to add the client name... The other is if you select the summary
tab... If it were me I would write a sub to add the name (if appropriate) and
then just call it from the on open event and from the sheet activate event...
Something like this...

Option Explicit

Private Sub Workbook_Open()
Call AddClient(ActiveSheet)
End Sub

Private Sub Workbook_SheetActivate(ByVal sh As Object)
Call AddClient(sh)
End Sub

Private Sub AddClient(ByVal sh As Worksheet)
With sh
If .Name = "Summary" Then
If Trim(.Range("A4").Value) = "" Then
.Range("A4").Value = InputBox("Please input the Client's Name")
End If
End If
End With
End Sub
--
HTH...

Jim Thomlinson


"Audrey" wrote:

Hi, I'm a VBA noob. At most I glean from the genius on this forum and copy
and paste your functions into my workbooks. I took a modified version of
this code directly from this forum, but I don't know how to change it so that
the input box will only pop up if the cell is blank.

Option Explicit
Private Sub Workbook_Open()

Dim ClientName As String

ClientName = InputBox("Please input the Client's Name")

Worksheets("Summary").Range("A4") = ClientName

End Sub

Also I only need the input box to pop up if the user is on the tab titled
"Summary," not as the book is opened.

Any help is greatly appreciated!

Thanks!

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make an input in a cell mandatory without leaving it blank Sandy Excel Discussion (Misc queries) 5 April 19th 23 02:11 PM
Start Cell B1 then find first blank cell, insert subtotal, next non blank, then next blank, sutotal cells in between......... [email protected][_2_] Excel Programming 2 June 7th 07 09:27 PM
Need macro to check if cell is not blank & previous cell is blank, copy information from row above & paste JenIT Excel Programming 4 April 12th 07 08:56 PM
Have user input converted to uppercase in same cell as input? Shannonn New Users to Excel 1 June 20th 06 03:19 AM
excel input 0 when cell blank or deleted by key or spacebar Curt Excel Worksheet Functions 5 November 5th 05 09:36 PM


All times are GMT +1. The time now is 06:49 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"