#1   Report Post  
Posted to microsoft.public.excel.misc
Leslieac
 
Posts: n/a
Default macro trigger

I have a column of cells (G18:G26) that the user can choose "Y" or "N"
directly in the cell. I need to have a macro triggered that opens a user
form (it is the same macro for all cells in that range), when they choose
"Y". I need to have the results of the user form printed on a unique line in
on a new worksheet tab. This way if they choose "Y" to more than one cell
(i.e. G18 & G19), I will get 2 sets of output data that don't overwrite each
other.

I have the user form created and working, but not for multiple cells. This
is what I have so far:

Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Belt Buff")

'specify an empty row in output sheet
iRow = 22


'copy the data to the database
With ws
.Cells(iRow, 12).Value = Me.txtHits.Value
.Cells(iRow, 13).Value = Me.txtTop.Value
.Cells(iRow, 14).Value = Me.txtSides.Value
End With

'clear the data
Me.txtHits.Value = ""
Me.txtTop.Value = ""
Me.txtSides.Value = ""

End Sub

Any help would be appreciated. Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default macro trigger

How about just showing the userform when they change exactly one cell?

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("g18:g26")) Is Nothing Then Exit Sub
If LCase(Target.Value) < "y" Then Exit Sub
UserForm1.Show
End Sub



Leslieac wrote:

I have a column of cells (G18:G26) that the user can choose "Y" or "N"
directly in the cell. I need to have a macro triggered that opens a user
form (it is the same macro for all cells in that range), when they choose
"Y". I need to have the results of the user form printed on a unique line in
on a new worksheet tab. This way if they choose "Y" to more than one cell
(i.e. G18 & G19), I will get 2 sets of output data that don't overwrite each
other.

I have the user form created and working, but not for multiple cells. This
is what I have so far:

Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Belt Buff")

'specify an empty row in output sheet
iRow = 22

'copy the data to the database
With ws
.Cells(iRow, 12).Value = Me.txtHits.Value
.Cells(iRow, 13).Value = Me.txtTop.Value
.Cells(iRow, 14).Value = Me.txtSides.Value
End With

'clear the data
Me.txtHits.Value = ""
Me.txtTop.Value = ""
Me.txtSides.Value = ""

End Sub

Any help would be appreciated. Thanks.


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
Leslieac
 
Posts: n/a
Default macro trigger

Thank You. That brings up the user form when those cells are choosen. I
have another question. My spreadsheet is constructing a finished part that
can have A - I components, so that is why they can answer "Y" to 9 choices
(g18:g26). Each component will have different dimensions, which is what the
User Form asks them to fill out. Currently, the user form is writing the
data they enter to row22, columns 12, 13, & 14. How can I increment this so
that if they enter more than one set of data, it will write to the next row
(i.e. row 23, row 24, etc.). Is this possible?

Thanks, Leslie

"Dave Peterson" wrote:

How about just showing the userform when they change exactly one cell?

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("g18:g26")) Is Nothing Then Exit Sub
If LCase(Target.Value) < "y" Then Exit Sub
UserForm1.Show
End Sub



Leslieac wrote:

I have a column of cells (G18:G26) that the user can choose "Y" or "N"
directly in the cell. I need to have a macro triggered that opens a user
form (it is the same macro for all cells in that range), when they choose
"Y". I need to have the results of the user form printed on a unique line in
on a new worksheet tab. This way if they choose "Y" to more than one cell
(i.e. G18 & G19), I will get 2 sets of output data that don't overwrite each
other.

I have the user form created and working, but not for multiple cells. This
is what I have so far:

Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Belt Buff")

'specify an empty row in output sheet
iRow = 22

'copy the data to the database
With ws
.Cells(iRow, 12).Value = Me.txtHits.Value
.Cells(iRow, 13).Value = Me.txtTop.Value
.Cells(iRow, 14).Value = Me.txtSides.Value
End With

'clear the data
Me.txtHits.Value = ""
Me.txtTop.Value = ""
Me.txtSides.Value = ""

End Sub

Any help would be appreciated. Thanks.


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default macro trigger

I'm not sure if this is a good fit, but it might give you an idea:

Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Belt Buff")

With ws
irow = .cells(.rows.count,12).end(xlup).row + 1
.Cells(iRow, 12).Value = Me.txtHits.Value
.Cells(iRow, 13).Value = Me.txtTop.Value
.Cells(iRow, 14).Value = Me.txtSides.Value
End With

'clear the data
Me.txtHits.Value = ""
Me.txtTop.Value = ""
Me.txtSides.Value = ""

End Sub

It uses column 12 to determine the next cell. You can change that to whatever
column always has data--or you could make sure that me.txthits.value is always
different from "" before you write to that cell. (That way it's always used.)



Leslieac wrote:

Thank You. That brings up the user form when those cells are choosen. I
have another question. My spreadsheet is constructing a finished part that
can have A - I components, so that is why they can answer "Y" to 9 choices
(g18:g26). Each component will have different dimensions, which is what the
User Form asks them to fill out. Currently, the user form is writing the
data they enter to row22, columns 12, 13, & 14. How can I increment this so
that if they enter more than one set of data, it will write to the next row
(i.e. row 23, row 24, etc.). Is this possible?

Thanks, Leslie

"Dave Peterson" wrote:

How about just showing the userform when they change exactly one cell?

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("g18:g26")) Is Nothing Then Exit Sub
If LCase(Target.Value) < "y" Then Exit Sub
UserForm1.Show
End Sub



Leslieac wrote:

I have a column of cells (G18:G26) that the user can choose "Y" or "N"
directly in the cell. I need to have a macro triggered that opens a user
form (it is the same macro for all cells in that range), when they choose
"Y". I need to have the results of the user form printed on a unique line in
on a new worksheet tab. This way if they choose "Y" to more than one cell
(i.e. G18 & G19), I will get 2 sets of output data that don't overwrite each
other.

I have the user form created and working, but not for multiple cells. This
is what I have so far:

Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Belt Buff")

'specify an empty row in output sheet
iRow = 22

'copy the data to the database
With ws
.Cells(iRow, 12).Value = Me.txtHits.Value
.Cells(iRow, 13).Value = Me.txtTop.Value
.Cells(iRow, 14).Value = Me.txtSides.Value
End With

'clear the data
Me.txtHits.Value = ""
Me.txtTop.Value = ""
Me.txtSides.Value = ""

End Sub

Any help would be appreciated. Thanks.


--

Dave Peterson


--

Dave Peterson
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
Search, Copy, Paste Macro in Excel [email protected] Excel Worksheet Functions 0 January 3rd 06 06:51 PM
Closing File Error jcliquidtension Excel Discussion (Misc queries) 4 October 20th 05 12:22 PM
Help with macro looping and color query function kevinm Excel Discussion (Misc queries) 10 May 26th 05 01:25 AM
Playing a macro from another workbook Jim Excel Discussion (Misc queries) 1 February 23rd 05 10:12 PM
Date macro Hiking Excel Discussion (Misc queries) 9 February 3rd 05 12:40 AM


All times are GMT +1. The time now is 07:22 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"