ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA Help required..........! (https://www.excelbanter.com/excel-programming/366026-vba-help-required.html)

Thyagaraj

VBA Help required..........!
 
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


WhytheQ

VBA Help required..........!
 
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


Thyagaraj wrote:

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




All times are GMT +1. The time now is 02:51 PM.

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