Results 1 to 3 of 3

How can I put this code into a loop..

Threaded View

  1. #1
    Registered User
    Join Date
    06-08-2015
    Location
    Bristol
    MS-Off Ver
    2013
    Posts
    75

    How can I put this code into a loop..

    Hiya,

    I've designed a spreadsheet withabout 15 editable fields. It has a 'save' button which runs a macro that moves everything that's been edited into another sheet.. One row per customer..

    mylookupvalue = Range("I1")
    
     Sheets("output doc").Select
     
    lnglastrow = Cells(Rows.Count, "A").End(xlUp).Row
    
    For Each cell In Range("A2:A" & lnglastrow)
     
     If cell.Value = mylookupvalue Then
     
     If strRowNoList = "" Then
     strRowNoList = strRowNoList & cell.Row
     
     End If
     
     End If
    
    Next cell
    
    If strRowNoList = "" Then strRowNoList = lnglastrow + 1
    
        Range("A" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$I$1"
        Range("B" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$H$4"
        Range("C" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$H$5"
        Range("D" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$H$6"
        Range("E" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$G$9"
        Range("F" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$B$29"
        Range("G" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$B$30"
         Range("H" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$B$31"
        Range("I" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$G$29"
        Range("J" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$G$30"
        Range("K" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$G$31"
        Range("L" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$B$35"
        Range("M" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$B$36"
        Range("N" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$B$37"
        Range("O" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$B$38"
        Range("P" & strRowNoList).Select
        ActiveCell.Formula = Now()
        Range("Q" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$G$1"
        Range("R" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$D$24"
        Range("S" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$E$24"
        Range("T" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$G$24"
        Range("U" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$H$24"
        Range("V" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$I$24"
        Range("W" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$A$25"
        Range("X" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$C$25"
        Range("Y" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$D$25"
            Range("Z" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$E$25"
        Range("AA" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$G$25"
        Range("AB" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$H$25"
        Range("AC" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$I$25"
        Range("AD" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$A$26"
        Range("AE" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$C$26"
        Range("AF" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$D$26"
            Range("AG" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$E$26"
        Range("AH" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$G$26"
        Range("AI" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$H$26"
        Range("AJ" & strRowNoList).Select
        ActiveCell.Formula = "='Plan on a Page'!$I$26"mylookupvalue = Range("I1")
    My question is, is there a better way of doing it... I'm thinking a loop but the cell reference is different on each line..


    Cheers,
    Last edited by purpleozzie; 01-29-2021 at 12:01 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA code to copy and loop (within a loop)
    By smarteloops in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-01-2017, 08:03 AM
  2. [SOLVED] How can I make this code shorter by using a loop. or there's any easier shorcuts code
    By romarkevinruiz in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-10-2014, 08:53 AM
  3. [SOLVED] How to put the code in a for loop or simplifing the code
    By willy292 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-09-2013, 06:34 AM
  4. VBA Loop Code Help
    By Gary_A_S in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-10-2013, 02:36 PM
  5. Code to turn this code into a loop doing muliple copies
    By fbplaya02 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-30-2013, 12:02 PM
  6. Excel 2007 : VBA Loop Code --- Help me :-)
    By EggHead in forum Excel General
    Replies: 2
    Last Post: 12-14-2009, 03:20 PM
  7. How To Loop with below code
    By pr4t3ek in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-10-2008, 09:39 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1