#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Macro Loop

Hi All,

I have a problem where I want to run a macro on all rows selected by the
user. The problem lies in, that the macro when ran can create x amount
of new rows below the current one, based on a number entered by the user.
So what I want to do, is after compleating one row, deselect the row,
and the (x) number of new rows created by processing the current row.

Here is my code:

Sub IndividualProducts()

Dim Answer As VbMsgBoxResult ' Answer to our question
Answer = MsgBox("This function assumes that the colour codes are
places in column A. If this is not the case the function will fail, and
there will be no undo function." & vbCrLf & " Do you wish to proceed?", _
vbQuestion + vbYesNo, "Confirm") ' Ask the question and get
the results
If Answer = vbNo Then
Exit Sub ' If user clicks no then exit sub
End If
Dim Product As Integer
Dim Description As Integer

Product = InputBox("Please enter the column which contains the
Product ID, i.e 1", "User input")
Description = InputBox("Please Enter the column which contains the
description field of the item", "User Input")


Dim myCell As Range ' Declaire are range
Dim myCell2 As Range ' Declaire are range
Dim myR As Range ' Declaire are range
Dim myCodes As Variant ' Colour codes
Dim myFullCodes As Variant ' Full Colour Names
Dim i As Integer ' Itterator

Set myR = Selection.Cells(1).EntireRow ' Get the selected row
Set myCell = myR.Cells(1, 1) ' Get the cell containign
colour codes
myCodes = Split(myCell.Value, ",") ' Split the cell, via
the delimiter
Set myCell2 = myR.Cells(1, 2)
myFullCodes = Split(myCell2.Value, ",")

If LBound(myCodes) < UBound(myCodes) Then
myR.Copy ' Copy the range
myR.Resize(UBound(myCodes) -
LBound(myCodes)).Offset(1).Insert ' Resize it
'myR.Resize(UBound(myCodes) -
LBound(myCodes)).Offset(UBound(myCodes)).Insert
For i = LBound(myCodes) To UBound(myCodes) ' Loop
through the colour code list
myCell(i + 1, Product).Value = myCell(i + 1,
Product).Value & "/" & myCodes(i) ' Create individual product codes
myCell2(i + 1, 4).Value = myCell2(i + 1, 4).Value &
" " & myFullCodes(i)
Next i
End If
End Sub

If anyone could help I would be forever in your debt.

Kind regards
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
Macro Loop stan Excel Discussion (Misc queries) 1 October 22nd 09 04:38 PM
Do until loop with use of another macro in loop The Excelerator Excel Programming 9 February 28th 07 02:28 AM
How Do I Get This Macro To Loop [email protected] Excel Programming 0 January 24th 07 05:09 PM
Loop Macro? Carmen Excel Programming 3 May 10th 05 01:00 PM
I Need Help with my loop macro Pete Excel Programming 1 January 16th 04 04:02 PM


All times are GMT +1. The time now is 02:56 AM.

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"