Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
dk dk is offline
external usenet poster
 
Posts: 129
Default UserForm or MsgBox to select from a list?

Using Excel 2007;
I have a list of sample records on Sheet3 in a range called "Samples"
(B4:Z14).
I want a macro to; Request the user to select one sample, then fill in
certain named cells on a report using the selected sample record. Here is
some code that fills one of the cells. This part is working fine.

Dim sampleno As Integer
sampleno = 1
Range("mfg") = Sheet3.Range("Samples").Cells(sampleno, 4)

How can I best have the user select one sample to supply the variable
"sampleno"?
The samples are numbered 1-10. I'm not familiar with UserForms but would
give it a try if that's the way to go.
If there is a better method, I'd be glad to see it.
Thanks much.

DK


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default UserForm or MsgBox to select from a list?

DK,

Perhaps?

sampleno = Application.InputBox("Choose a sample number between 1 and 10",
Type:=1)

HTH,
Bernie
MS Excel MVP



"DK" wrote in message
...
Using Excel 2007;
I have a list of sample records on Sheet3 in a range called "Samples"
(B4:Z14).
I want a macro to; Request the user to select one sample, then fill in
certain named cells on a report using the selected sample record. Here is
some code that fills one of the cells. This part is working fine.

Dim sampleno As Integer
sampleno = 1
Range("mfg") = Sheet3.Range("Samples").Cells(sampleno, 4)

How can I best have the user select one sample to supply the variable
"sampleno"?
The samples are numbered 1-10. I'm not familiar with UserForms but would
give it a try if that's the way to go.
If there is a better method, I'd be glad to see it.
Thanks much.

DK


  #3   Report Post  
Posted to microsoft.public.excel.programming
dk dk is offline
external usenet poster
 
Posts: 129
Default UserForm or MsgBox to select from a list?

Bernie,
Thank you for the tip. That worked nicely.
I added an if statement to handle the 'Cancel'.
If sampleno = 0 Then
Exit Sub
This seems to work ok. Is that the appropriate method of handling Cancel?
DK

"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
DK,

Perhaps?

sampleno = Application.InputBox("Choose a sample number between 1 and 10",
Type:=1)

HTH,
Bernie
MS Excel MVP



"DK" wrote in message
...
Using Excel 2007;
I have a list of sample records on Sheet3 in a range called "Samples"
(B4:Z14).
I want a macro to; Request the user to select one sample, then fill in
certain named cells on a report using the selected sample record. Here
is some code that fills one of the cells. This part is working fine.

Dim sampleno As Integer
sampleno = 1
Range("mfg") = Sheet3.Range("Samples").Cells(sampleno, 4)

How can I best have the user select one sample to supply the variable
"sampleno"?
The samples are numbered 1-10. I'm not familiar with UserForms but would
give it a try if that's the way to go.
If there is a better method, I'd be glad to see it.
Thanks much.

DK




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default UserForm or MsgBox to select from a list?

It is an OK way, since you dimmed sampleno as an integer, Excel casts the
False return that cancel generates into an integer, which translates as 0.
A more formal way would be to dim sampleno as a variant, and then it would
be False.... I would stick with your way.... VBA is definitely an "if it
ain't broke" kind of language.

Bernie


"DK" wrote in message
...
Bernie,
Thank you for the tip. That worked nicely.
I added an if statement to handle the 'Cancel'.
If sampleno = 0 Then
Exit Sub
This seems to work ok. Is that the appropriate method of handling Cancel?
DK

"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
DK,

Perhaps?

sampleno = Application.InputBox("Choose a sample number between 1 and
10", Type:=1)

HTH,
Bernie
MS Excel MVP



"DK" wrote in message
...
Using Excel 2007;
I have a list of sample records on Sheet3 in a range called "Samples"
(B4:Z14).
I want a macro to; Request the user to select one sample, then fill in
certain named cells on a report using the selected sample record. Here
is some code that fills one of the cells. This part is working fine.

Dim sampleno As Integer
sampleno = 1
Range("mfg") = Sheet3.Range("Samples").Cells(sampleno, 4)

How can I best have the user select one sample to supply the variable
"sampleno"?
The samples are numbered 1-10. I'm not familiar with UserForms but would
give it a try if that's the way to go.
If there is a better method, I'd be glad to see it.
Thanks much.

DK





  #5   Report Post  
Posted to microsoft.public.excel.programming
dk dk is offline
external usenet poster
 
Posts: 129
Default UserForm or MsgBox to select from a list?

Thanks very much for the insite.
DK

"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
It is an OK way, since you dimmed sampleno as an integer, Excel casts the
False return that cancel generates into an integer, which translates as 0.
A more formal way would be to dim sampleno as a variant, and then it would
be False.... I would stick with your way.... VBA is definitely an "if it
ain't broke" kind of language.

Bernie


"DK" wrote in message
...
Bernie,
Thank you for the tip. That worked nicely.
I added an if statement to handle the 'Cancel'.
If sampleno = 0 Then
Exit Sub
This seems to work ok. Is that the appropriate method of handling Cancel?
DK

"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
DK,

Perhaps?

sampleno = Application.InputBox("Choose a sample number between 1 and
10", Type:=1)

HTH,
Bernie
MS Excel MVP



"DK" wrote in message
...
Using Excel 2007;
I have a list of sample records on Sheet3 in a range called "Samples"
(B4:Z14).
I want a macro to; Request the user to select one sample, then fill in
certain named cells on a report using the selected sample record. Here
is some code that fills one of the cells. This part is working fine.

Dim sampleno As Integer
sampleno = 1
Range("mfg") = Sheet3.Range("Samples").Cells(sampleno, 4)

How can I best have the user select one sample to supply the variable
"sampleno"?
The samples are numbered 1-10. I'm not familiar with UserForms but
would give it a try if that's the way to go.
If there is a better method, I'd be glad to see it.
Thanks much.

DK







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
UserForm MsgBox problems jeq214 Excel Programming 6 March 21st 09 10:05 PM
MsgBox Replacement w/ an UserForm Chuckles123[_37_] Excel Programming 0 October 10th 04 04:17 PM
MsgBox Replacement w/ an UserForm Chuckles123[_36_] Excel Programming 2 October 10th 04 04:05 PM
MsgBox Replacement w/ an UserForm Chuckles123[_34_] Excel Programming 2 October 9th 04 05:48 PM
MsgBox Replacement w/ an UserForm Chuckles123[_31_] Excel Programming 0 October 9th 04 02:38 PM


All times are GMT +1. The time now is 12:37 PM.

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

About Us

"It's about Microsoft Excel"