+ Reply to Thread
Results 1 to 2 of 2

Loop with variables

  1. #1
    Registered User
    Join Date
    10-08-2008
    Location
    Edinburgh
    Posts
    3

    Loop with variables

    Hi guys,

    I'm looking to run this code on a loop but amend the columns each time.

    Range("a4:a238").Select
    mypath = Range("a1").Value & ""
    mytext = Range("a2").Value
    If Not Len(mytext) = 0 Then
    f = FreeFile
    Open mypath & mytext & "" For Output As f
    For i = 1 To Selection.Rows.Count
    Print #f, Selection.Cells(i, 1).Text
    Next
    Close f
    End If

    so next loop would be running on
    Range("b4:b238").Select
    mypath = Range("b1").Value & ""
    mytext = Range("b2").Value

    Probably very simple but I'm getting myself in knots here
    Thanks
    D

  2. #2
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628

    Re: Loop with variables

    You could use this code:
    Please Login or Register  to view this content.
    Regards,
    Antonio

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Loop Variables
    By cocacrave in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-18-2015, 08:10 AM
  2. How to loop through VBA defined variables
    By killpaddy in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 08-27-2014, 10:24 AM
  3. [SOLVED] Define Variables in a For loop
    By chaddug in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-08-2014, 05:39 PM
  4. [SOLVED] loop, do while, with variables - help
    By fredderf81 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-21-2014, 03:56 PM
  5. Incrementing variables in a Loop
    By sungsam in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-17-2011, 11:32 AM
  6. Is it possible to create variables in a loop..
    By shishi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-03-2006, 03:25 PM
  7. [SOLVED] Write variables from a loop, once only
    By Novaloc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-11-2005, 12:05 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