Loop

Amjtoo

New Member
Joined
May 9, 2020
Messages
12
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

I have an excel sheet where there are data with empty rows in between.
My aim is to cut a range of data based on a cell value in column A and paste the data in a new worksheet by creating one.
Eg- if there is the word "name" in any row in col A then from that cell it will select xltoright and xldown , cut the entire data n paste in a new worksheet in the same file.
Again it will come back to the original sheet n scout through the rows to find cell with "name" and do the same operation but only paste in another new worksheet.
The data is not continuous so I can't run do until isempty loop

Kindly suggest if it's possible to achieve it by coding n if yes,how?
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
if there is the word "name" in any row in col A then from that cell it will select xltoright and xldown , cut the entire data n paste in a new worksheet in the same file.

Try this

VBA Code:
Sub LoopCells()
  Dim r As Range, f As Range, cell As String
  Application.ScreenUpdating = False
  Set r = Range("A:A")
  Set f = r.Find("Name", , xlValues, xlWhole)
  If Not f Is Nothing Then
    cell = f.Address
    Do
      Range(f, f.End(2).End(4)).Copy
      Sheets.Add after:=Sheets(Sheets.Count)
      ActiveSheet.Paste
      Set f = r.FindNext(f)
    Loop While Not f Is Nothing And f.Address <> cell
  End If
  Application.CutCopyMode = False
End Sub
 
Upvote 0
Try this

VBA Code:
Sub LoopCells()
  Dim r As Range, f As Range, cell As String
  Application.ScreenUpdating = False
  Set r = Range("A:A")
  Set f = r.Find("Name", , xlValues, xlWhole)
  If Not f Is Nothing Then
    cell = f.Address
    Do
      Range(f, f.End(2).End(4)).Copy
      Sheets.Add after:=Sheets(Sheets.Count)
      ActiveSheet.Paste
      Set f = r.FindNext(f)
    Loop While Not f Is Nothing And f.Address <> cell
  End If
  Application.CutCopyMode = False
End Sub


Okay I will try this
 
Upvote 0
Try this

VBA Code:
Sub LoopCells()
  Dim r As Range, f As Range, cell As String
  Application.ScreenUpdating = False
  Set r = Range("A:A")
  Set f = r.Find("Name", , xlValues, xlWhole)
  If Not f Is Nothing Then
    cell = f.Address
    Do
      Range(f, f.End(2).End(4)).Copy
      Sheets.Add after:=Sheets(Sheets.Count)
      ActiveSheet.Paste
      Set f = r.FindNext(f)
    Loop While Not f Is Nothing And f.Address <> cell
  End If
  Application.CutCopyMode = False
End Sub
Try this

VBA Code:
Sub LoopCells()
  Dim r As Range, f As Range, cell As String
  Application.ScreenUpdating = False
  Set r = Range("A:A")
  Set f = r.Find("Name", , xlValues, xlWhole)
  If Not f Is Nothing Then
    cell = f.Address
    Do
      Range(f, f.End(2).End(4)).Copy
      Sheets.Add after:=Sheets(Sheets.Count)
      ActiveSheet.Paste
      Set f = r.FindNext(f)
    Loop While Not f Is Nothing And f.Address <> cell
  End If
  Application.CutCopyMode = False
End Sub


Hi DanteAmor,

Thanks a lot for your help.. the code is working fine.
Appreciate your time and effort.
If possible please help me out with another issue that am facing.

I am filtering a set of about 1400 rows(with header) based on 3 column values. Then m trying to delete the hidden rows. But the last 16 rows are getting retained though they don't satisfy the 3 conditions.

Looking forward to your solution
 
Upvote 0
Sounds like it's another problem than this thread. Create a new thread, that way you can receive more opportunities for help, don't forget to give examples of your data and the result you need.
 
Upvote 0

Forum statistics

Threads
1,215,767
Messages
6,126,767
Members
449,336
Latest member
p17tootie

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top