PC Review


Reply
Thread Tools Rate Thread

Another Stock Macro Question

 
 
Materialised
Guest
Posts: n/a
 
      20th Apr 2007
Hi,
Thank you to all who replies to my previous post. It seems I had
misunderstood the problem.

(Going back to my BMX bike example)
We have the following data:

ProdID Desc Price
2374 BMX Bicycle £99.99

Now this bike comes in various colours (Red Green and Blue), so what I
want to be able to do, is slect the entire row, and run a macro. Which
would prompt the user to specify what colours the product was available
in. So for this example, the user wouldd type "R,G,B".
Which would then replace to current line, with the following:

ProdID Desc Price
2374/R BMX Bicycle £99.99
2374/G BMX Bicycle £99.99
2374/B BMX Bicycle £99.99

Does anyone know how I would acomplish this?

Kind Regards
 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      20th Apr 2007

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Const WS_RANGE As String = "2:20" '<== change to suit
Dim ans, aryOptions
Dim i As Long
On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
ans = InputBox("What colours?")
If ans = False Then Exit Sub
aryOptions = Split(ans, ",")
Target.Offset(1, 0).Resize(UBound(aryOptions) -
LBound(aryOptions)).EntireRow.Insert
Target.EntireRow.AutoFill Target.Resize(UBound(aryOptions) -
LBound(aryOptions) + 1).EntireRow
For i = LBound(aryOptions) To UBound(aryOptions)
Me.Cells(Target.Offset(i, 0).Row, "A").Value =
Me.Cells(Target.Offset(i, 0).Row, "A").Value & "\" & aryOptions(i)
Me.Cells(Target.Offset(i, 0).Row, "D").Value =
Me.Cells(Target.Row, "D").Value
Next i
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.



--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Materialised" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
> Thank you to all who replies to my previous post. It seems I had
> misunderstood the problem.
>
> (Going back to my BMX bike example)
> We have the following data:
>
> ProdID Desc Price
> 2374 BMX Bicycle £99.99
>
> Now this bike comes in various colours (Red Green and Blue), so what I
> want to be able to do, is slect the entire row, and run a macro. Which
> would prompt the user to specify what colours the product was available
> in. So for this example, the user wouldd type "R,G,B".
> Which would then replace to current line, with the following:
>
> ProdID Desc Price
> 2374/R BMX Bicycle £99.99
> 2374/G BMX Bicycle £99.99
> 2374/B BMX Bicycle £99.99
>
> Does anyone know how I would acomplish this?
>
> Kind Regards



 
Reply With Quote
 
Materialised
Guest
Posts: n/a
 
      20th Apr 2007
Bob Phillips wrote:
> Private Sub Worksheet_SelectionChange(ByVal Target As Range)
> Const WS_RANGE As String = "2:20" '<== change to suit
> Dim ans, aryOptions
> Dim i As Long
> On Error GoTo ws_exit
> Application.EnableEvents = False
>
> If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
> With Target
> ans = InputBox("What colours?")
> If ans = False Then Exit Sub
> aryOptions = Split(ans, ",")
> Target.Offset(1, 0).Resize(UBound(aryOptions) -
> LBound(aryOptions)).EntireRow.Insert
> Target.EntireRow.AutoFill Target.Resize(UBound(aryOptions) -
> LBound(aryOptions) + 1).EntireRow
> For i = LBound(aryOptions) To UBound(aryOptions)
> Me.Cells(Target.Offset(i, 0).Row, "A").Value =
> Me.Cells(Target.Offset(i, 0).Row, "A").Value & "\" & aryOptions(i)
> Me.Cells(Target.Offset(i, 0).Row, "D").Value =
> Me.Cells(Target.Row, "D").Value
> Next i
> End With
> End If
>
> ws_exit:
> Application.EnableEvents = True
> End Sub
>
> 'This is worksheet event code, which means that it needs to be
> 'placed in the appropriate worksheet code module, not a standard
> 'code module. To do this, right-click on the sheet tab, select
> 'the View Code option from the menu, and paste the code in.
>
>
>

Thanks Bob, that worked great.
As so often happens, my manager has now decided he would like to do it
another way. (Going Back to my BMX example)

Colour Codes ProdID Desc Price
2374 BMX Bicycle £99.99

A new row has been inserted, where the user will type the various colour
codes into. So for example:

Colour Codes ProdID Desc Price
W,R,B 2374 BMX Bicycle £99.99

The user would then select this row, and run a macro, and would have:
Colour Codes ProdID Desc Price
W,R,B 2374/W BMX Bicycle £99.99
W,R,B 2374/R BMX Bicycle £99.99
W,R,B 2374/B BMX Bicycle £99.99

I would imagine the pincipal is very similar to what you earlier
presented me with. But to be totally honest, I am no windows programmer,
Im a UNIX admin, and its been over 10 years since I even made a ripple
in the water with any windows programming. So any advise or pointers you
could give me would great.

Thanks
Mick
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stock Macro Loop Materialised Microsoft Excel Programming 1 26th Apr 2007 01:02 PM
Excel - Stock Macro Help Materialised Microsoft Excel Programming 2 19th Apr 2007 03:33 PM
Macro For Stock Control =?Utf-8?B?Q2hhY2t5?= Microsoft Excel Programming 0 28th Mar 2007 12:18 AM
Macro to automate MSN Stock Quotes? =?Utf-8?B?UGF1bA==?= Microsoft Excel Programming 2 3rd Sep 2006 03:07 AM
Excel macro to get stock quotes off the www Bob Benjamin Microsoft Excel Programming 1 3rd Nov 2003 03:39 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:31 AM.