Exporting multiple ranges to a text file (RANGE OF OBJECT GLOBAL FAILED)

pbbspl

Board Regular
Joined
Apr 13, 2004
Messages
51
Hi Board

This below mentioned script was written to save cell values of a6.. a210 and a1501..a1600 to a text file in g:\ with name text1.txt .

Excel returns me with a Run time error of 1004 ( Method Range of Object _Global Failed)

For Each t In Range("A1501:A1600").Rows

at this line.

Appreciate your help in solving this.


Dim ca As Range, cb As Range, s As Range, t As Range
Dim outputa As String, outputb As String

Dim l1 As String
Dim l2 As String
Dim l3 As String
Dim l4 As String
Dim l5 As String
Dim l6 As String

l1 = "[MARKET_WATCH_GROUP_NAMES]"
l2 = "VALUE=LTD"
l3 = "[LTD]"
l4 = "VALUE="
l5 = "[TOKEN_LIST_MAX_SIZE]"
l6 = "Value = 5000"


For Each s In Range("A6:A210").Rows
For Each ca In s.Cells
outputa = outputa & "nse_cm|" & ca.Value & ","
Next ca
outputa = outputa
'& vbNewLine
Next s


For Each t In Range("A1501:A1600").Rows
For Each cb In t.Cells
outputb = outputb & "nse_fo|" & cb.Value & ","
Next cb
outputb = outputb
'& vbNewLine
Next t

Open "G:\text1.txt" For Output As #1
Print #1 , l1 & vbNewLine & l2 & vbNewLine & l3 & vbNewLine & l4 & outputa & outputb & vbNewLine & l5 & vbNewLine & l6 & vbNewLine
Close

a = MsgBox("ARE YOU DONE UPLOADING?", _
vbYesNo)
If a = vbNo Then Cancel = True
If a = vbYes Then

Range("F501:I1494").Select
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top