Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2008

Tip: Looking for answers? Try searching our database.

Macro works - any suggestions on improvements?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brad - 23 Jan 2008 02:00 GMT
Other than remove Key3 logic -
This will only be used by me.

Sub ExportCashValues()
   Dim Filename As String
   Dim Numrows As Long
   Dim i As Long
   Dim j As Long
   Dim dur As Long
   Dim data As Double
   Dim key1 As Range
   Dim key2 As Range
   Dim key3 As Range
   Dim key4 As Range
   Dim key5 As Range
   Set key1 = shtCash.Range("d1:d96064")
   Set key2 = shtCash.Range("e1:e96064")
   Set key3 = shtCash.Range("g1:g96064")
   Set key4 = shtCash.Range("h1:h96064")
   Set key5 = shtCash.Range("j1:s96064")
   Filename = "C:\myTempDir\cashvalu.txt"
   Open Filename For Output As #1
   For i = 1 To 96094
       For j = 1 To 10
           dur = key4(i) + j - 1
           If key5(i, j) <> "" Then
               data = key5(i, j) / 100
               Print #1, key1(i); ","; key2(i); ","; dur; ","; Format(data,
"0.00")
           End If
       Next j
   Next i
   Close #1
End Sub
Joel - 23 Jan 2008 13:31 GMT
I wouldn't hard code the number 96064.  either make it a constant

Const EndRow = 96064
Set key1 = shtCash.Range("d1:d" & EndRow)

or find the last row

Lastrow = Range("D" & Rows.Count).end(xlup).Row
Set key1 = shtCash.Range("d1:d" & LastRow)

> Other than remove Key3 logic -
> This will only be used by me.
[quoted text clipped - 30 lines]
>     Close #1
> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.