VBA Help required..........!

  • Thread starter Thread starter Thyagaraj
  • Start date Start date
T

Thyagaraj

Hi,Friends,

Assuming i have variable no. of rows in a sheet each time i run the
macro.The macro should check for the First four characters of column A
in each row, Insert a worksheet in the name of those first four digits
if the digits are changed in the next row and copy the Entire row to
the new sheet.


If any confusion in understanding the above please revert back.


Regards
Thyagaraj
 
something like the below should help:

Option Explicit

Sub AddSheets()

Dim i As Integer

Dim myNarrative As String
Dim myPrevNarrative As String
Dim myTableSheet As Worksheet

On Error Resume Next

Set myTableSheet = ActiveSheet
With myTableSheet
For i = 2 To .Cells(Rows.Count, 1).End(xlUp).Row
myNarrative = Left(.Cells(i, 1), 4)
myPrevNarrative = Left(.Cells(i - 1, 1), 4)
If myPrevNarrative <> myNarrative Then
With ActiveWorkbook.Worksheets.Add
.Name = myNarrative
End With
.Rows(i).Copy Sheets(myNarrative).Rows(1)
End If
Next
End With

End Sub

Hope this helps
Jason
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top