Using an Array to capture data in a loop

danresnick.dr

New Member
Joined
Jan 4, 2011
Messages
7
Excel Gurus -

I need your help on this one. I am trying to incorporate an Array into this For loop in order to capture the 'Name' (variable is nm) during the looping and then display a message box showing all names that were updated.

The process is basically:
Look at column O, and for each row, if the value in column O is TRUE, copy that row and paste it to the corresponding row in another sheet. If not, skip over that row.

My current code has the user click thru a message box for each row that is updated. I would like one box to pop up at the end showing a list of all of the names that have been updated.

Here is my code:
Code:
 For l = 16 To s
        If Sheets("Search").Range("O" & l) = True Then
        'if it is true, that means they want to update it, perform the copy and paste
    
        'get and set copy ranges
        Set crg = Sheets("Search").Range("C" & l & ":M" & l)
        nm = Sheets("Search").Range("C" & l).Value
 
    
        'get and set paste ranges
        Rp = Sheets("Search").Range("P" & l).Value + 1
        Set prg = Sheets("Raw Data").Range("A" & Rp & ":K" & Rp)
    
        'Copy and paste new values
        crg.Copy
        prg.PasteSpecial Paste:=xlPasteValues
        Application.CutCopyMode = False
        
        
        MsgBox "You have updated " & nm & ""
      
        Else
        'if it is false, that means they do not want to update it, skip this row
        Selection.Offset(1, 0).Select
        End If
    
    Next l

Thanks, I really appreciate all your help!
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
untested:
Code:
Sub Macro3()
nm = "You have updated "
For l = 16 To s
  If Sheets("Search").Range("O" & l) = True Then
    'if it is true, that means they want to update it, perform the copy and paste
    'get and set copy ranges
    Set crg = Sheets("Search").Range("C" & l & ":M" & l)
    nm = nm & vbLf & Sheets("Search").Range("C" & l).Value
    'get and set paste ranges
    Rp = Sheets("Search").Range("P" & l).Value + 1
    Set prg = Sheets("Raw Data").Range("A" & Rp & ":K" & Rp)
    'Copy and paste new values
    crg.Copy
    prg.PasteSpecial Paste:=xlPasteValues
    Application.CutCopyMode = False
  Else
    'if it is false, that means they do not want to update it, skip this row
    Selection.Offset(1, 0).Select
  End If
Next l
MsgBox nm
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,558
Messages
6,179,512
Members
452,921
Latest member
BBQKING

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top