code not working correctly

Status
Not open for further replies.

redspanna

Well-known Member
Joined
Jul 27, 2005
Messages
1,604
Office Version
  1. 365
Platform
  1. Windows
Hi all

This code was suggested to me many moons ago...

It searches through column A to match a text string. Once found it will then copy the adjacent number value into certain column - next available line - then it is meant to delete the found value from column B and matching text string in column A


Code:
Set Mycell = Sheets("Sorted Data").Range("A:A").Find(What:="*Test1*") 
While Not Mycell Is Nothing
Mycell.Offset(0, 1).Copy Range("C65536").End(xlUp)(2)
Mycell.Clear
Set Mycell = Range("A:A").FindNext
Wend


Set Mycell = Sheets("Sorted Data").Range("A:A").Find(What:="*Test2*") 
While Not Mycell Is Nothing
Mycell.Offset(0, 1).Copy Range("D65536").End(xlUp)(2)
Mycell.Clear
Set Mycell = Range("A:A").FindNext
Wend


Set Mycell = Sheets("Sorted Data").Range("A:A").Find(What:="*Test3*") 
While Not Mycell Is Nothing
Mycell.Offset(0, 1).Copy Range("E65536").End(xlUp)(2)
Mycell.Clear
Set Mycell = Range("A:A").FindNext
Wend

Set Mycell = Sheets("Sorted Data").Range("A:A").Find(What:="*Test4*") 
While Not Mycell Is Nothing
Mycell.Offset(0, 1).Copy Range("F65536").End(xlUp)(2)
Mycell.Clear
Set Mycell = Range("A:A").FindNext
Wend


Set Mycell = Sheets("Sorted Data").Range("A:A").Find(What:="*Test5*") 
While Not Mycell Is Nothing
Mycell.Offset(0, 1).Copy Range("L65536").End(xlUp)(2)
Mycell.Clear
Set Mycell = Range("A:A").FindNext
Wend


weird problem is that code works and does what t should, but doesn't always delete the number value from column B

example


[table="width: 150, class: grid"]
[tr]
[td]Test1[/td]
[td]50[/td]
[/tr]
[tr]
[td]Test2[/td]
[td]23[/td]
[/tr]
[tr]
[td]Test3[/td]
[td]100[/td]
[/tr]
[tr]
[td]Test4[/td]
[td]99[/td]
[/tr]
[tr]
[td]Test5[/td]
[td]65[/td]
[/tr]
[/table]

once code runs, some expected data is left behind when should be deleted....


[table="width: 150, class: grid"]
[tr]
[td]Test1[/td]
[td]50[/td]
[/tr]
[tr]
[td]Test2[/td]
[td]23[/td]
[/tr]
[tr]
[td][/td]
[td]100[/td]
[/tr]
[tr]
[td][/td]
[td]99[/td]
[/tr]
[tr]
[td][/td]
[td]65[/td]
[/tr]
[/table]


any explanation, or suggest better way of working code?

Many thanks in advance
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Status
Not open for further replies.

Forum statistics

Threads
1,223,896
Messages
6,175,260
Members
452,627
Latest member
KitkatToby

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