MrExcel Message Board


Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old Mar 30th, 2004, 07:16 PM   #1
MiskaTorn
 
Join Date: Mar 2004
Posts: 155
Default Looping help

I am very new to this programming, and I have taken a pre-written script and am having troubles trying to figure out methods on how I can make this script bend to my needs.

I need for this script to automatically set the length value, but this value is differen't for each column.

I have about 30 columns and each one needs to be a different length. Though it is standard for each time I run the macro so it can be a set variable.

BTW, this script exports all the active colums and rows into a text-delimited text file.

Code:
Sub Export()
  Dim Length
  Dim z%, s%
  Dim TMP$
  Length = InputBox("FieldLength:")
  If Length = "" Then Length = 20
  Open "test.txt" For Output As #1
  For z = 1 To ActiveSheet.UsedRange.Rows.Count
    For s = 1 To ActiveSheet.UsedRange.Columns.Count
      TMP = TMP & CStr(Cells(z, s).Text) & String(Length - Len(Cells(z, s).Text), " ")
      Next s
      Print #1, TMP
      TMP = ""
  Next z
  Close 1
  MsgBox "The data names are stored under the following address:" & Chr(13) & _
    CurDir() & "\test.txt"
End Sub
MiskaTorn is offline   Reply With Quote
 

Bookmarks

Thread Tools
Display Modes

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 On

Forum Jump


All times are GMT +1. The time now is 01:03 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
All contents Copyright 1998-2009 by MrExcel Consulting.