I'm trying to use the following code to import multiple .txt into separate separate sheets in a workbook. In all of the worksheets it fails to space delimit the last row and from worksheet 2 onward it also fails to copy the first line of the .txt file. All the txt. files are the exactly the same format. Any help appreciated.
Sub CombineTextFiles()
Dim FilesToOpen
Dim x As Integer
Dim wkbAll As Workbook
Dim wkbTemp As Workbook
Dim sDelimiter As String
On Error GoTo ErrHandler
Application.ScreenUpdating = False
FilesToOpen = Application.GetOpenFilename _
(FileFilter:="Text Files (*.txt), *.txt", _
MultiSelect:=True, Title:="Text Files to Open")
If TypeName(FilesToOpen) = "Boolean" Then
MsgBox "No Files were selected"
GoTo ExitHandler
End If
x = 1
Set wkbTemp = Workbooks.Open(Filename:=FilesToOpen(x))
wkbTemp.Sheets(1).Copy
Set wkbAll = ActiveWorkbook
wkbTemp.Close (False)
wkbAll.Worksheets(x).Columns("A:A").TextToColumns _
Destination:=Range("A1"), DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False, Semicolon:=False, _
Comma:=False, Space:=True, Other:=False, OtherChar:="|"
Dim lastrowA As Long
Dim lastrowB As Long
Dim sheetname As String
With ActiveSheet
lastrowA = .Cells(.Rows.Count, "A").End(xlUp).Row
lastrowB = .Cells(.Rows.Count, "B").End(xlUp).Row
sheetname = ActiveSheet.Name
Range("a1").EntireColumn.Insert
Range("a1").Value = sheetname
Range("a2" & ":a" & lastrowB).Value = Range("a1")
Range("a1").EntireRow.Insert
End With
x = x + 1
While x <= UBound(FilesToOpen)
Set wkbTemp = Workbooks.Open(Filename:=FilesToOpen(x))
With wkbAll
wkbTemp.Sheets(1).Move After:=.Sheets(.Sheets.Count)
.Worksheets(x).Columns("A:A").TextToColumns _
Destination:=Range("A1"), DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False, Semicolon:=False, _
Comma:=False, Space:=True, Other:=False
End With
With ActiveSheet
lastrowA = .Cells(.Rows.Count, "A").End(xlUp).Row
lastrowB = .Cells(.Rows.Count, "B").End(xlUp).Row
sheetname = ActiveSheet.Name
Range("a1").Value = sheetname
Range("a2" & ":a" & lastrowB).Value = Range("a1")
Range("a1").EntireRow.Insert
End With
x = x + 1
Wend
ExitHandler:
Application.ScreenUpdating = True
Set wkbAll = Nothing
Set wkbTemp = Nothing
Exit Sub
ErrHandler:
MsgBox Err.Description
Resume ExitHandler
End Sub
If you make a minimal, complete, and verifiable example, you would probably find the mistake yourself. However, by your description for the first row, I guess the problem is here:
With ActiveSheet
lastrowA = .Cells(.Rows.Count, "A").End(xlUp).Row
lastrowB = .Cells(.Rows.Count, "B").End(xlUp).Row
sheetname = ActiveSheet.Name
Range("a1").EntireColumn.Insert
Range("a1").Value = sheetname
Range("a2" & ":a" & lastrowB).Value = Range("a1")
Range("a1").EntireRow.Insert
End With
You need to declare the ranges like this:
With ActiveSheet
lastrowA = .Cells(.Rows.Count, "A").End(xlUp).Row
lastrowB = .Cells(.Rows.Count, "B").End(xlUp).Row
sheetname = ActiveSheet.Name
.Range("a1").EntireColumn.Insert
.Range("a1").Value = sheetname
.Range("a2" & ":a" & lastrowB).Value = .Range("a1")
.Range("a1").EntireRow.Insert
End With
See the dots, they make the difference. If the code is located in a worksheet, then the ranges take the worksheet they are located to, as a Parent worksheet.
Related
I'm writing code in VBA, which should collect file .001 type, convert it to an Excel file (space delimited). Then I need to split it to different files (N steps) and convert it back to .001 file (like original). But I can't reproduce the original .001 form. Can I attach the original file? Are there different ways to split .001 files to N different .001 files?
Sub Import_file()
Dim MFC_name As String
Sheet1.Cells.ClearContents
Range("A1").Select
file_path = Application.GetOpenFilename()
Workbooks.OpenText filename:=file_path, Origin:=437 _
, StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=False _
, Space:=False, Other:=False, FieldInfo:=Array(1, 1), _
TrailingMinusNumbers:=True
Columns("A:G").Select
Selection.Copy
Windows("code_test.xlsm").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
ActiveWindow.ActivateNext
MFC_name = ActiveWorkbook.Name
Application.DisplayAlerts = False
ActiveWindow.Close
Range("I1").Value = MFC_name
Range("A1").Select
End Sub
Sub split_and_write()
Dim totalRows As Long
Dim newBook As Workbook
Dim curRow As Long
Dim filename As Variant
Dim lastRow As Long
Dim path As String
Dim myFileName As String
Dim r As Integer
totalRows = ThisWorkbook.Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
For curRow = 8 To totalRows Step 1244
Set newBook = Workbooks.Add
With ThisWorkbook.Sheets("Sheet1")
'copy of the 7 rows with name+tool number+time and paste it to new workbook
ThisWorkbook.Worksheets("Sheet1").Range("A1:B7").Copy newBook.Sheets("Sheet1").Range("A1")
'copy and creation of the seperate workboks
.Rows(curRow & ":" & curRow + 1243).EntireRow.Copy newBook.Sheets("Sheet1").Range("A8")
'copy xcl to txt for each workbook
lastRow = newBook.Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
'creation of .txt file path
path = "C:\XCL_FP\MFC_flow_cal\MFC_test\"
myFileName = InputBox("name?")
myFileName = myFileName & ".001" 'Providing extantion for the file
myFileName = path & myFileName
'writhing .xcl file to.001
Open myFileName For Output As #1
For r = 1 To lastRow
Print #1, Range("A" & r); " "; Range("B" & r)
Next r
Close #1
Application.DisplayAlerts = False
ActiveWorkbook.Close SaveChanges:=False
Application.DisplayAlerts = True
'filename = Application.GetSaveAsFilename
'newBook.saveas filename:=filename
End With
Next curRow
End Sub
I picked up this code from the web. It merges several Excel files to single file (each in separate sheets).
The files the DATA is imported from don't automatically close. This means that I need to manually close 8-10 files and "Do not Save" them, and that takes lots of time. What is the missing code?
Option Explicit
Sub CombineExcelFiles()
Dim FilesToOpen
Dim x As Integer
Dim wkbAll As Workbook
Dim wkbTemp As Workbook
Dim sDelimiter As String
On Error GoTo ErrHandler
Application.ScreenUpdating = False
sDelimiter = "|"
FilesToOpen = Application.GetOpenFilename _
(FileFilter:="Excel Files (*.*xl*), *.*xl*", _
MultiSelect:=True, Title:="Excel Files to Open")
If TypeName(FilesToOpen) = "Boolean" Then
MsgBox "No Files were selected"
GoTo ExitHandler
End If
x = 1
Set wkbTemp = Workbooks.Open(Filename:=FilesToOpen(x))
wkbTemp.Sheets(1).Copy
Set wkbAll = ActiveWorkbook
wkbTemp.Close (False)
wkbAll.Worksheets(x).Columns("A:A").TextToColumns _
Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, _
Tab:=False, Semicolon:=False, _
Comma:=False, Space:=False, _
Other:=True, OtherChar:="|"
x = x + 1
While x <= UBound(FilesToOpen)
Set wkbTemp = Workbooks.Open(Filename:=FilesToOpen(x))
With wkbAll
wkbTemp.Sheets(1).Move After:=.Sheets(.Sheets.Count)
.Worksheets(x).Columns("A:A").TextToColumns _
Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, _
Tab:=False, Semicolon:=False, _
Comma:=False, Space:=False, _
Other:=True, OtherChar:=sDelimiter
End With
x = x + 1
Wend
ExitHandler:
Application.ScreenUpdating = True
Set wkbAll = Nothing
Set wkbTemp = Nothing
Exit Sub
ErrHandler:
MsgBox Err.Description
Resume ExitHandler
End Sub
wkbTemp.Close False should close the workbook without saving it.
But another question is why do you process the first file outside the While loop? I see no reason for this. Therefore we can shorten that code to:
Option Explicit
Public Sub CombineExcelFiles()
Dim FilesToOpen
Dim x As Integer
Dim wkbAll As Workbook
Dim wkbTemp As Workbook
Dim sDelimiter As String
On Error GoTo ErrHandler
Application.ScreenUpdating = False
sDelimiter = "|"
FilesToOpen = Application.GetOpenFilename _
(FileFilter:="Excel Files (*.*xl*), *.*xl*", _
MultiSelect:=True, Title:="Excel Files to Open")
If TypeName(FilesToOpen) = "Boolean" Then
MsgBox "No Files were selected"
GoTo ExitHandler
End If
x = 1
Set wkbAll = ActiveWorkbook
While x <= UBound(FilesToOpen)
Set wkbTemp = Workbooks.Open(Filename:=FilesToOpen(x))
With wkbAll
wkbTemp.Sheets(1).Move After:=.Sheets(.Sheets.Count)
wkbTemp.Close False
.Worksheets(x).Columns("A:A").TextToColumns _
Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, _
Tab:=False, Semicolon:=False, _
Comma:=False, Space:=False, _
Other:=True, OtherChar:=sDelimiter
End With
x = x + 1
Wend
ExitHandler:
Application.ScreenUpdating = True
Set wkbAll = Nothing
Set wkbTemp = Nothing
Exit Sub
ErrHandler:
MsgBox Err.Description
Resume ExitHandler
End Sub
Some Important Notes
I recommend to avoid ActiveWorkbook if possible because it is not a defined workbook but any workbook that is active at just this moment. Also note that there is a difference between ActiveWorkbook and ThisWorkbook (which is a defined workbook. It is the workbook the code runs at this point).*
Another thing is that .Worksheets(x) can be, but not necessarily must be the actually moved worksheet. I would say because you move the new sheet after the last sheet you also need to access the last sheet here: .Worksheets(.Worksheets.Count).
Also there is a difference between using Sheets and Worksheets. The Sheets collection contains worksheets but also charts etc, but the Worksheets collection only contains worksheets. Therefore you should decide which one is correct, I recommend always to use Worksheets unless you really need Sheets.
And I see no need for setting the variables to nothing.
Set wkbAll = Nothing
Set wkbTemp = Nothing
If I'm not totally wrong then Excel does this automatically when the procedure ends.
Introduction: With continuation to my previous question, initially, my previous code (with the help from Stack exchange experts) works fine.
Problem: But next time when I import the files again (which I have to do monthly), it creates duplicate Sheets. So I would like to modify my project as follows.
On clicking "Import text files" button, the VBA code:
Check the existing Workbook for the sheet names matching the text file name. If existing, clear the contents of the sheet and copy the data into the sheet.
For example, If my text file names are like "Data_REQ1", "Data_REQ2" and so on until Data_REQ30, the code should check for sheets starting with Data_REQ1, if exists clear the contents, copy the data from text file Data_REQ1 into the sheet Data_REQ1 and so on for other sheets.
Pseudo code:
Check Sheets existence
If Sheet name exists Then
Clear contents
Copy the data from text file having sheet name=textfile name
Else
Create the Sheet and import the data into the sheet
Here is my full code
Sub copydata()
Dim FilesToOpen
Dim x As Integer
Dim wkbAll As Workbook
Dim sDelimiter As String
Dim ws As Worksheet
Dim lastCol As Integer
Dim lastRow As Integer
Dim TextFileName As String
On Error GoTo ErrHandler
Application.ScreenUpdating = False
sDelimiter = "|"
FilesToOpen = Application.GetOpenFilename _
(FileFilter:="Text Files (*.txt), *.txt", _
MultiSelect:=True, Title:="Text Files to Open")
If TypeName(FilesToOpen) = "Boolean" Then
MsgBox "No Files were selected"
GoTo ExitHandler
End If
'Open First text File then format the data with delimiter and copy the data
x = 1
With Workbooks.Open(filename:=FilesToOpen(x))
TextFileName = Sheets(1).Name
.Worksheets(1).Columns("A:A").TextToColumns _
Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, _
Tab:=False, Semicolon:=False, Comma:=False, Space:=False, _
Other:=True, OtherChar:="|"
lastCol = Sheets(TextFileName).Range("a1").End(xlToRight).Column
lastRow = Sheets(TextFileName).Cells(65536, lastCol).End(xlUp).Row
Selection.Copy
.Close False
'clear the contents of the sheets, copy the data into the sheet with same name as text file
With ThisWorkbook.Worksheets(TextFileName)
lastCol = Sheets(TextFileName).Range("a1").End(xlToRight).Column
lastRow = Sheets(TextFileName).Cells(65536, lastCol).End(xlUp).Row
Sheets(TextFileName).Range("a1", ActiveSheet.Cells(lastRow, lastCol)).Select
Selection.ClearContents
Sheets(TextFileName).Range("A1").PasteSpecial
End With
End With
'This loop is for other files , if the above code works for 1 file, I will change this code for other files
x = x + 1
While x <= UBound(FilesToOpen)
With Workbooks.Open(filename:=FilesToOpen(x))
.Worksheets(1).Columns("A:A").TextToColumns _
Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, _
Tab:=False, Semicolon:=False, _
Comma:=False, Space:=False, _
Other:=True, OtherChar:=sDelimiter
.Sheets(1).Move After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
End With
x = x + 1
Wend
Call fitWidth(ws)
wkbAll.Save
ExitHandler:
Application.ScreenUpdating = True
Set wkbAll = Nothing
Exit Sub
ErrHandler:
MsgBox Err.Description
Resume ExitHandler
End Sub
Sub fitWidth(ws As Worksheet)
For Each ws In Sheets
If LCase(ws.Name) Like "data_req*" Then
ws.Cells.EntireColumn.AutoFit
End If
Next
End Sub
Here is the code which I tried to change from previous version
Previous version:
With Workbooks.Open(filename:=FilesToOpen(x))
.Worksheets(1).Columns("A:A").TextToColumns _
Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, _
Tab:=False, Semicolon:=False, Comma:=False, Space:=False, _
Other:=True, OtherChar:="|"
.Sheets(1).Copy After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
.Close False
Present Version
x = 1
With Workbooks.Open(fileName:=FilesToOpen(x))
TextFileName = Sheets(1).Name
.Worksheets(1).Columns("A:A").TextToColumns _
Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, _
Tab:=False, Semicolon:=False, Comma:=False, Space:=False, _
Other:=True, OtherChar:="|"
lastCol = Sheets(TextFileName).Range("a1").End(xlToRight).Column
lastRow = Sheets(TextFileName).Cells(65536, lastCol).End(xlUp).Row
Selection.Copy
.Close False
'clear the contents of the sheets, copy the data into the sheet with same > name as text file
With ThisWorkbook.Worksheets(TextFileName)
lastCol = Sheets(TextFileName).Range("a1").End(xlToRight).Column
lastRow = Sheets(TextFileName).Cells(65536, lastCol).End(xlUp).Row
Sheets(TextFileName).Range("a1", ActiveSheet.Cells(lastRow, lastCol)).Select
Selection.ClearContents
Sheets(TextFileName).Range("A1").PasteSpecial
End With
My Request: With this change, I am able to clear contents, but not pasting the data. Any suggestions or any code better than this code will be appreciated.
Consider using QueryTables to import text files. No need to copy/paste across temp workbooks:
Sub ImportTXTFiles()
Dim fso As Object
Dim xlsheet As Worksheet
Dim qt As QueryTable
Dim txtfilesToOpen As Variant, txtfile As Variant
Application.ScreenUpdating = False
Set fso = CreateObject("Scripting.FileSystemObject")
txtfilesToOpen = Application.GetOpenFilename _
(FileFilter:="Text Files (*.txt), *.txt", _
MultiSelect:=True, Title:="Text Files to Open")
For Each txtfile In txtfilesToOpen
' FINDS EXISTING WORKSHEET
For Each xlsheet In ThisWorkbook.Worksheets
If xlsheet.Name = Replace(fso.GetFileName(txtfile), ".txt", "") Then
xlsheet.Activate
GoTo ImportData
End If
Next xlsheet
' CREATES NEW WORKSHEET IF NOT FOUND
Set xlsheet = ThisWorkbook.Worksheets.Add( _
After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count))
xlsheet.Name = Replace(fso.GetFileName(txtfile), ".txt", "")
xlsheet.Activate
GoTo ImportData
ImportData:
' DELETE EXISTING DATA
ActiveSheet.Range("A:Z").EntireColumn.Delete xlShiftToLeft
' IMPORT DATA FROM TEXT FILE
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & txtfile, _
Destination:=ActiveSheet.Cells(1, 1))
.TextFileParseType = xlDelimited
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = "|"
.Refresh BackgroundQuery:=False
End With
For Each qt In ActiveSheet.QueryTables
qt.Delete
Next qt
Next txtfile
Application.ScreenUpdating = True
MsgBox "Successfully imported text files!", vbInformation, "SUCCESSFUL IMPORT"
Set fso = Nothing
End Sub
I am working to make an automated template that imports multiple csv files into multiple sheets in an excel template that I have created.
So far I have one sheet in the template that has a table named Results and a column named Login ID. I wrote the following script to automatically create sheets and name them. My table data starts on row 7.
Sub Prepare_Report()
Dim WS As Worksheet
' Go to the results page
Sheets("Results Page").Select
' Create all additional sheets from Login ID field in the results table
Dim N As Long, I As Long
N = Range("Results[Login ID]").Rows.Count + 6
For I = 7 To N
aName = Worksheets("Results Page").Range("C" & I).Value
Set WS = Sheets.Add(After:=Sheets(Worksheets.Count))
WS.Name = aName
Next I
Each CSV file I have to import is named after one of the Login ID's as well, and they will be located in the same folder as the template I am creating.
the CSV files will need a slight modification to separate the date and time from the first column.
' Columns("A:A").Select
' Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
' Columns("B:B").Select
' Selection.Cut Destination:=Columns("A:A")
' Columns("A:A").Select
' Selection.TextToColumns Destination:=Range("A1"), DataType:=xlFixedWidth, _
' FieldInfo:=Array(Array(0, 1), Array(10, 1)), TrailingMinusNumbers:=True
' Columns("A:A").Select
' Selection.NumberFormat = "mm/dd/yy;#"
' Columns("B:B").Select
' Columns("B:B").EntireColumn.AutoFit
'
Any ideas if I am on the right track or how to best solve my CSV import woes would be much appreciated.
This will do what you want!
Sub CombineTextFiles()
Dim FilesToOpen
Dim x As Integer
Dim wkbAll As Workbook
Dim wkbTemp As Workbook
Dim sDelimiter As String
On Error GoTo ErrHandler
Application.ScreenUpdating = False
sDelimiter = "|"
FilesToOpen = Application.GetOpenFilename _
(FileFilter:="CSV Files (*.csv), *.csv", _
MultiSelect:=True, Title:="CSV Files to Open")
If TypeName(FilesToOpen) = "Boolean" Then
MsgBox "No Files were selected"
GoTo ExitHandler
End If
x = 1
Set wkbTemp = Workbooks.Open(Filename:=FilesToOpen(x))
wkbTemp.Sheets(1).Copy
Set wkbAll = ActiveWorkbook
wkbTemp.Close (False)
wkbAll.Worksheets(x).Columns("A:A").TextToColumns _
Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, _
Tab:=False, Semicolon:=False, _
Comma:=False, Space:=False, _
Other:=True, OtherChar:="|"
x = x + 1
While x <= UBound(FilesToOpen)
Set wkbTemp = Workbooks.Open(Filename:=FilesToOpen(x))
With wkbAll
wkbTemp.Sheets(1).Move After:=.Sheets(.Sheets.Count)
.Worksheets(x).Columns("A:A").TextToColumns _
Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, _
Tab:=False, Semicolon:=False, _
Comma:=False, Space:=False, _
Other:=True, OtherChar:=sDelimiter
End With
x = x + 1
Wend
ExitHandler:
Application.ScreenUpdating = True
Set wkbAll = Nothing
Set wkbTemp = Nothing
Exit Sub
ErrHandler:
MsgBox Err.Description
Resume ExitHandler
End Sub
Ok, so I am trying to perform a batch interpolation macro on some files in a folder and would like to know how I can refrence the ActiveRange from the .XLSM and feed it back into the for next loop for each selected file.
Sub Batch_Interpolate_Blanks()
Dim SaveDriveDir As String
Dim MyPath As String
Dim Fname As Variant
Dim N As Long
Dim FnameInLoop As String
Dim mybook As Workbook
Dim myRange As Range
Dim myRange2 As Range
Dim EntireRange As Range
SaveDriveDir = CurDir
MyPath = Application.DefaultFilePath
ChDrive MyPath
ChDir MyPath
Fname = Application.GetOpenFilename(Title:="Select a file or files", MultiSelect:=True)
If IsArray(Fname) Then
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
RangeSelect: Set myRange = Application.InputBox(Prompt:= _
"Please Select the Column you wish to Interpolate. ", _
Title:="InputBox", Type:=8)
If myRange Is Nothing Then
Else
myRange.Select
End If
For N = LBound(Fname) To UBound(Fname)
FnameInLoop = Right(Fname(N), Len(Fname(N)) - InStrRev(Fname(N), Application.PathSeparator, , 1))
If bIsBookOpen(FnameInLoop) = False Then
Set mybook = Nothing
On Error Resume Next
Set mybook = Workbooks.Open(Fname(N))
On Error GoTo 0
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Columns("A").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=True, Other:=False, FieldInfo _
:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1)), _
TrailingMinusNumbers:=True
'Here is where I think I should reference RangeSelect Somehow!!
'Something Like Workbooks.("Otherworkbook").Activate then make active range = RangeSelect
Start = ActiveCell
EndRow = Range("A" & Rows.Count).End(xlUp).Row
Do Until ActiveCell.Row = EndRow
Selection.Offset(1, 0).Select
'Perform my macro function below etc
If someone can think of a way to do this it would be great! Any more info needed Please Ask!
Tom
Edit:Essentially I want to reference the active range of a 'Master Workbook' and select it in a destination workbook without an absolute reference!
Something along these lines. Note you don't need to Select ranges in order to work with them...
Dim c As Range
'using .Cells(1) in case user selected >1 cell
Set c = mybook.ActiveSheet.Range(myRange.Cells(1).Address())
EndRow = Range("A" & Rows.Count).End(xlUp).Row
Do While c.Row <= EndRow
c.Offset(1, 0).Select
'etc....
Set c = c.Offset(1, 0)
Loop