ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sub will not find Column "A" (https://www.excelbanter.com/excel-programming/351745-sub-will-not-find-column.html)

hazel

Sub will not find Column "A"
 
Hi Everybody

The following ( there could be up to 400 lines) is received as an attachment
in an Email the attachment is in Notepad. Which I Cut and paste into Excel.
4100,WM7886,255,1404
4100,WM5589,255,1473
4100,WM6458,253,1230
4100,WM6467,254,966
using the following macro

Sub Macro3()

Sheets("main").Select
Selection.TextToColumns Destination:=Range("F2"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False,
Tab:=True, _
Semicolon:=False, Comma:=True, Space:=False, Other:=True,
FieldInfo:= _
Array(Array(1, 9), Array(2, 1), Array(3, 1), Array(4, 1)),
TrailingMinusNumbers:= _
True


Range("F2:H4").Select
Selection.Cut
Range("A2").Select
ActiveSheet.Paste
End Sub

I then use the following code I asked help for last week and Patrick Molloy
kindly helped and it worked OK --- however having a strange problem after cut
and paste to column "A" I now find the sub will not insert the data into the
respective rows and sheets apparently because it cannot find column "A" ---
however if I manually enter the data in Col "A" e.g. WM7886 it finds the
correct row and col and inserts the other cols of data. have tried changing
from text to general and number in Format cells all to no avail.

Option Explicit
Sub PopData()
Sheets("main").Select
Dim source As Range
Dim ws As Worksheet
Dim cell As Range
Dim index As Long
For Each ws In Worksheets
If ws.Name < "main" Then
For Each cell In Range(Range("A2"), Range("A2").End(xlDown))
index = matched(cell.Value, ws)
If index 0 Then
ws.Cells(index, 200).End(xlToLeft).Offset(0, 1) = cell.Offset(, 1)
ws.Cells(index, 200).End(xlToLeft).Offset(0, 1) = cell.Offset(, 2)
End If
Next 'item
End If
Next 'sheet
End Sub
Function matched(item As String, ws As Worksheet) As Long
On Error Resume Next
matched = WorksheetFunction.Match(item, ws.Columns(1), False)
On Error GoTo 0
End Function

Has anybody any idea's


--
Many thanks

hazel


All times are GMT +1. The time now is 07:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com