ChrisRamsden
New Member
- Joined
- Sep 26, 2018
- Messages
- 24
Hi Everyone,
I am a brand new member, although i have been using MrExcel for tips and information for a few years now. I am currently writing an excel macro to pull data from another workbook by finding the number 4 and using offset to pick the cells i want to copy and paste.
The macro is doing it's job but it then causes a Runtime Error 13 - Type Mismatch. It feels like it is running through the loop and then causing an error when it tries to run through again. I have spent hours searching for the answer with no luck so i am calling on all you experts to help teach me something new and help me move forward with my macro:
As i am new if i do anything wrong please correct me and i will remember for next time. I know there is probably a better way to do this but if i can just stop the Runtime Error it actually pulls all the information i need. The line where the error is showing is:
Thank you in advance,
Chris
I am a brand new member, although i have been using MrExcel for tips and information for a few years now. I am currently writing an excel macro to pull data from another workbook by finding the number 4 and using offset to pick the cells i want to copy and paste.
The macro is doing it's job but it then causes a Runtime Error 13 - Type Mismatch. It feels like it is running through the loop and then causing an error when it tries to run through again. I have spent hours searching for the answer with no luck so i am calling on all you experts to help teach me something new and help me move forward with my macro:
Code:
Sub TR1797N1()
Application.ScreenUpdating = False
Dim lRow As Long
Dim cell As Object
'Change text format from single cell to multiple cells
Windows("TR1797 N1.txt").Activate
Columns("A: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), Array(6, 1), _
Array(7, 1), Array(8, 1), Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1 _
)), TrailingMinusNumbers:=True
'Select data and copy and paste into spreadsheet. This contains a loop through the data
lRow = Range("A" & Rows.Count).End(xlUp).Row
For Each cell In Range("A1:A500")
If Left(cell.Value, 1) = "4" Then
cell.Select
ActiveCell.Copy
ThisWorkbook.Activate
Sheets("TR1797").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
Windows("TR1797 N1.txt").Activate
ActiveCell.Offset(0, 1).Copy
ThisWorkbook.Activate
Sheets("TR1797").Range("B" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
Windows("TR1797 N1.txt").Activate
ActiveCell.Offset(0, 2).Copy
ThisWorkbook.Activate
Sheets("TR1797").Range("C" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
Windows("TR1797 N1.txt").Activate
ActiveCell.Offset(0, 4).Copy
ThisWorkbook.Activate
Sheets("TR1797").Range("D" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
Windows("TR1797 N1.txt").Activate
ActiveCell.Offset(0, 5).Copy
ThisWorkbook.Activate
Sheets("TR1797").Range("E" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
Windows("TR1797 N1.txt").Activate
ActiveCell.Offset(1, 0).Copy
ThisWorkbook.Activate
Sheets("TR1797").Range("F" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
Windows("TR1797 N1.txt").Activate
ActiveCell.Offset(6, 2).Copy
ThisWorkbook.Activate
Sheets("TR1797").Range("G" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
Windows("TR1797 N1.txt").Activate
ActiveCell.Offset(6, 3).Copy
ThisWorkbook.Activate
Sheets("TR1797").Range("H" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
Windows("TR1797 N1.txt").Activate
End If
Next
End Sub
As i am new if i do anything wrong please correct me and i will remember for next time. I know there is probably a better way to do this but if i can just stop the Runtime Error it actually pulls all the information i need. The line where the error is showing is:
Code:
If Left(cell.Value, 1) = "4" Then
Thank you in advance,
Chris