Macro works - any suggestions on improvements?

B

Brad

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
 
J

Joel

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top