Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default find/delete data on different tabs

Hello all,

I have a tab named "untitled" and a tab named "bluecard_homeplanaid".
I have data in tab "untitled" column "B". They're numbers such as
200906180333.
I need code to that takes the number in the first cell "B1" in tab
"untitled" and searches column "B" in tab "bluecard_homeplanaid". If found,
then that row in tab "bluecard_homeplanaid" would be deleted. This process
repeats for all of the numbers in column "B" in tab "untitled.

Note: The amount of data in column "B" , tab "untitled" changes daily.

thanks in advance!!!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default find/delete data on different tabs

see if this does what you want. Suggest that you make back-up of your data
before testing.

Sub DeleteData()

Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim StartRow As Long
Dim EndRow As Long
Dim Lr As Long
Dim FoundCell As Range
Dim Search As String
Dim icount As Long

With ThisWorkbook

Set ws1 = .Worksheets("untitled")
Set ws2 = .Worksheets("bluecard_homeplanaid")

End With

'assume you have a header in row 1
StartRow = 2

icount = 0

With ws1

EndRow = .Cells(.Rows.Count, "B").End(xlUp).Row

For Lr = StartRow To EndRow

Search = .Cells(Lr, 2).Value

If Search < "" Then

Set FoundCell = ws2.Columns(2).Find(Search, _
After:=ws2.Cells(1, 2), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

If FoundCell Is Nothing = False Then

FoundCell.EntireRow.Delete

icount = icount + 1

End If

End If

Next

End With

msg = MsgBox(icount & " Records Deleted", vbInformation, "Delete Data")

End Sub

--
jb


"Peruanos72" wrote:

Hello all,

I have a tab named "untitled" and a tab named "bluecard_homeplanaid".
I have data in tab "untitled" column "B". They're numbers such as
200906180333.
I need code to that takes the number in the first cell "B1" in tab
"untitled" and searches column "B" in tab "bluecard_homeplanaid". If found,
then that row in tab "bluecard_homeplanaid" would be deleted. This process
repeats for all of the numbers in column "B" in tab "untitled.

Note: The amount of data in column "B" , tab "untitled" changes daily.

thanks in advance!!!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default find/delete data on different tabs

Hi John,

I'm getting a "Subscript out of range" error when the code hits
Set ws1 = .Worksheets("untitled")

i moved that worksheet so it's the first worksheet but the error still
comes up. I only have the two worksheets in the workbook.

Thoughts??

"john" wrote:

see if this does what you want. Suggest that you make back-up of your data
before testing.

Sub DeleteData()

Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim StartRow As Long
Dim EndRow As Long
Dim Lr As Long
Dim FoundCell As Range
Dim Search As String
Dim icount As Long

With ThisWorkbook

Set ws1 = .Worksheets("untitled")
Set ws2 = .Worksheets("bluecard_homeplanaid")

End With

'assume you have a header in row 1
StartRow = 2

icount = 0

With ws1

EndRow = .Cells(.Rows.Count, "B").End(xlUp).Row

For Lr = StartRow To EndRow

Search = .Cells(Lr, 2).Value

If Search < "" Then

Set FoundCell = ws2.Columns(2).Find(Search, _
After:=ws2.Cells(1, 2), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

If FoundCell Is Nothing = False Then

FoundCell.EntireRow.Delete

icount = icount + 1

End If

End If

Next

End With

msg = MsgBox(icount & " Records Deleted", vbInformation, "Delete Data")

End Sub

--
jb


"Peruanos72" wrote:

Hello all,

I have a tab named "untitled" and a tab named "bluecard_homeplanaid".
I have data in tab "untitled" column "B". They're numbers such as
200906180333.
I need code to that takes the number in the first cell "B1" in tab
"untitled" and searches column "B" in tab "bluecard_homeplanaid". If found,
then that row in tab "bluecard_homeplanaid" would be deleted. This process
repeats for all of the numbers in column "B" in tab "untitled.

Note: The amount of data in column "B" , tab "untitled" changes daily.

thanks in advance!!!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default find/delete data on different tabs

It means it can't find a worksheet with that name - I copied the names from
your post - check the spellings & try again.
--
jb


"Peruanos72" wrote:

Hi John,

I'm getting a "Subscript out of range" error when the code hits
Set ws1 = .Worksheets("untitled")

i moved that worksheet so it's the first worksheet but the error still
comes up. I only have the two worksheets in the workbook.

Thoughts??

"john" wrote:

see if this does what you want. Suggest that you make back-up of your data
before testing.

Sub DeleteData()

Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim StartRow As Long
Dim EndRow As Long
Dim Lr As Long
Dim FoundCell As Range
Dim Search As String
Dim icount As Long

With ThisWorkbook

Set ws1 = .Worksheets("untitled")
Set ws2 = .Worksheets("bluecard_homeplanaid")

End With

'assume you have a header in row 1
StartRow = 2

icount = 0

With ws1

EndRow = .Cells(.Rows.Count, "B").End(xlUp).Row

For Lr = StartRow To EndRow

Search = .Cells(Lr, 2).Value

If Search < "" Then

Set FoundCell = ws2.Columns(2).Find(Search, _
After:=ws2.Cells(1, 2), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

If FoundCell Is Nothing = False Then

FoundCell.EntireRow.Delete

icount = icount + 1

End If

End If

Next

End With

msg = MsgBox(icount & " Records Deleted", vbInformation, "Delete Data")

End Sub

--
jb


"Peruanos72" wrote:

Hello all,

I have a tab named "untitled" and a tab named "bluecard_homeplanaid".
I have data in tab "untitled" column "B". They're numbers such as
200906180333.
I need code to that takes the number in the first cell "B1" in tab
"untitled" and searches column "B" in tab "bluecard_homeplanaid". If found,
then that row in tab "bluecard_homeplanaid" would be deleted. This process
repeats for all of the numbers in column "B" in tab "untitled.

Note: The amount of data in column "B" , tab "untitled" changes daily.

thanks in advance!!!

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default find/delete data on different tabs

The spelling was correct. my code copies my tabs to a new workbook so the
master file is not touched and my code runs in the new workbook from the
master file. it appears your code doesn't work in the new book that's created
but it does work if done in the master file.

Is there a way to run your code in my new workbook?

"john" wrote:

It means it can't find a worksheet with that name - I copied the names from
your post - check the spellings & try again.
--
jb


"Peruanos72" wrote:

Hi John,

I'm getting a "Subscript out of range" error when the code hits
Set ws1 = .Worksheets("untitled")

i moved that worksheet so it's the first worksheet but the error still
comes up. I only have the two worksheets in the workbook.

Thoughts??

"john" wrote:

see if this does what you want. Suggest that you make back-up of your data
before testing.

Sub DeleteData()

Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim StartRow As Long
Dim EndRow As Long
Dim Lr As Long
Dim FoundCell As Range
Dim Search As String
Dim icount As Long

With ThisWorkbook

Set ws1 = .Worksheets("untitled")
Set ws2 = .Worksheets("bluecard_homeplanaid")

End With

'assume you have a header in row 1
StartRow = 2

icount = 0

With ws1

EndRow = .Cells(.Rows.Count, "B").End(xlUp).Row

For Lr = StartRow To EndRow

Search = .Cells(Lr, 2).Value

If Search < "" Then

Set FoundCell = ws2.Columns(2).Find(Search, _
After:=ws2.Cells(1, 2), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

If FoundCell Is Nothing = False Then

FoundCell.EntireRow.Delete

icount = icount + 1

End If

End If

Next

End With

msg = MsgBox(icount & " Records Deleted", vbInformation, "Delete Data")

End Sub

--
jb


"Peruanos72" wrote:

Hello all,

I have a tab named "untitled" and a tab named "bluecard_homeplanaid".
I have data in tab "untitled" column "B". They're numbers such as
200906180333.
I need code to that takes the number in the first cell "B1" in tab
"untitled" and searches column "B" in tab "bluecard_homeplanaid". If found,
then that row in tab "bluecard_homeplanaid" would be deleted. This process
repeats for all of the numbers in column "B" in tab "untitled.

Note: The amount of data in column "B" , tab "untitled" changes daily.

thanks in advance!!!



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default find/delete data on different tabs

did not see that requirement in your original post.
Yes is the short answer but it would help if you post all the code you are
using.

I am about to leave office & out for evening will respond asap
--
jb


"Peruanos72" wrote:

The spelling was correct. my code copies my tabs to a new workbook so the
master file is not touched and my code runs in the new workbook from the
master file. it appears your code doesn't work in the new book that's created
but it does work if done in the master file.

Is there a way to run your code in my new workbook?

"john" wrote:

It means it can't find a worksheet with that name - I copied the names from
your post - check the spellings & try again.
--
jb


"Peruanos72" wrote:

Hi John,

I'm getting a "Subscript out of range" error when the code hits
Set ws1 = .Worksheets("untitled")

i moved that worksheet so it's the first worksheet but the error still
comes up. I only have the two worksheets in the workbook.

Thoughts??

"john" wrote:

see if this does what you want. Suggest that you make back-up of your data
before testing.

Sub DeleteData()

Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim StartRow As Long
Dim EndRow As Long
Dim Lr As Long
Dim FoundCell As Range
Dim Search As String
Dim icount As Long

With ThisWorkbook

Set ws1 = .Worksheets("untitled")
Set ws2 = .Worksheets("bluecard_homeplanaid")

End With

'assume you have a header in row 1
StartRow = 2

icount = 0

With ws1

EndRow = .Cells(.Rows.Count, "B").End(xlUp).Row

For Lr = StartRow To EndRow

Search = .Cells(Lr, 2).Value

If Search < "" Then

Set FoundCell = ws2.Columns(2).Find(Search, _
After:=ws2.Cells(1, 2), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

If FoundCell Is Nothing = False Then

FoundCell.EntireRow.Delete

icount = icount + 1

End If

End If

Next

End With

msg = MsgBox(icount & " Records Deleted", vbInformation, "Delete Data")

End Sub

--
jb


"Peruanos72" wrote:

Hello all,

I have a tab named "untitled" and a tab named "bluecard_homeplanaid".
I have data in tab "untitled" column "B". They're numbers such as
200906180333.
I need code to that takes the number in the first cell "B1" in tab
"untitled" and searches column "B" in tab "bluecard_homeplanaid". If found,
then that row in tab "bluecard_homeplanaid" would be deleted. This process
repeats for all of the numbers in column "B" in tab "untitled.

Note: The amount of data in column "B" , tab "untitled" changes daily.

thanks in advance!!!

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
how to find the data after we delete bayu Excel Discussion (Misc queries) 1 October 11th 08 05:54 PM
Delete if find a data format Junior728 Excel Programming 2 May 11th 07 09:50 AM
How can I find and delete tabs and carriage returns ? JeffEE Excel Discussion (Misc queries) 1 November 11th 05 02:47 PM
Find last row of data and delete empty rows Pat Excel Programming 3 February 17th 05 12:34 AM
Find and Delete data in a column rahul_chatterjee[_2_] Excel Programming 4 October 25th 04 11:08 PM


All times are GMT +1. The time now is 10:32 AM.

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

About Us

"It's about Microsoft Excel"