Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default simple macro gives error .. help needed

hi all,

Can someone pls tell me what is wrong with this code? (It just wont
run!...)

I am trying to split data from worksheet "RAW data" into two worksheets
"IR data" and "FLS data", based on the length of the string in column A
of RAW data. The macro is intended to run until entry in column A
becomes empty.

Sub splitdata()
Dim i As Variant
Dim j As Variant
Dim k As Variant
Dim a As Variant
Dim c As Range 'current
Dim n As Range 'next

Set c = Range("A2")

i = 2
j = 2
k = 2

Do While Not IsEmpty(c)
Set n = c.Offset(1, 0)
a = Len(Cells(i, "A"))
If a < 9 Then
IRdata!Range(Cells(j, "A"), Cells(j, "O")) =
RAWdata!Range(Cells(i, "A"), Cells(i, "O"))
j = j + 1
Else
FLSdata!Range(Cells(k, "A"), Cells(k, "O")) =
RAWdata!Range(Cells(i, "A"), Cells(i, "O"))
k = k + 1
End If
i = i + 1
Set c = n
Loop
End Sub

Thnx,

Joe.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default simple macro gives error .. help needed

Joe,

Try this:

Sub splitdata()

Dim i As Long
Dim j As Long
Dim k As Long
Dim lastrow as Long


Set ws1 = Worksheets("RAWdata")
Set ws2 = Worksheets("IRdata")
Set ws3 = Worksheets("FLSdata")


j = 2
k = 2

lastrow = ws1.Cells(Rows.Count, "A").End(xlUp).Row

With ws1
For i = 2 To lastrow
If Len(.Cells(i, 1)) < 9 Then
.Range("a" & i & ":o" & i).Copy ws2.Range("a" & j)
j = j + 1
Else
.Range("a" & i & ":o" & i).Copy ws3.Range("a" & k)
k = k + 1
End If

Next i
End With
End Sub

HTH

"Joe" wrote:

hi all,

Can someone pls tell me what is wrong with this code? (It just wont
run!...)

I am trying to split data from worksheet "RAW data" into two worksheets
"IR data" and "FLS data", based on the length of the string in column A
of RAW data. The macro is intended to run until entry in column A
becomes empty.

Sub splitdata()
Dim i As Variant
Dim j As Variant
Dim k As Variant
Dim a As Variant
Dim c As Range 'current
Dim n As Range 'next

Set c = Range("A2")

i = 2
j = 2
k = 2

Do While Not IsEmpty(c)
Set n = c.Offset(1, 0)
a = Len(Cells(i, "A"))
If a < 9 Then
IRdata!Range(Cells(j, "A"), Cells(j, "O")) =
RAWdata!Range(Cells(i, "A"), Cells(i, "O"))
j = j + 1
Else
FLSdata!Range(Cells(k, "A"), Cells(k, "O")) =
RAWdata!Range(Cells(i, "A"), Cells(i, "O"))
k = k + 1
End If
i = i + 1
Set c = n
Loop
End Sub

Thnx,

Joe.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default simple macro gives error .. help needed

Toppers,

Thanks a lot.

- Joe.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
simple Macro needed ipbr21054 New Users to Excel 1 November 18th 10 07:57 PM
Simple formula needed shane Excel Discussion (Misc queries) 5 October 18th 07 11:27 PM
Simple Cut & Paste Macro needed :) dstock[_13_] Excel Programming 7 June 22nd 05 03:08 PM
Simple macro needed to export a worksheet RobG Excel Programming 9 April 11th 05 10:13 AM
simple help needed please ian123[_20_] Excel Programming 4 December 18th 03 02:00 AM


All times are GMT +1. The time now is 08:13 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"