crazybuckeyeguy

New Member
Joined
Apr 15, 2017
Messages
49
I know I am over thinking this. I have a spread sheet that we are adding a function for TR. the report we create is stupid and will list them as such:

BUCKNER, JENNIFERMulti_Skill 6:30 AM 3:00 PMMulti_Skill 6:30 AM 3:00 PM
TR 6:30 AM 3:00 PM
CAREFOOT, CHRISTINAMulti_Skill 6:30 AM 3:00 PMTR 6:30 AM 3:00 PM
Multi_Skill 6:30 AM 3:00 PM
<colgroup><col width="68" style="width: 51pt; mso-width-source: userset; mso-width-alt: 2486;"> <col width="72" style="width: 54pt; mso-width-source: userset; mso-width-alt: 2633;"> <col width="30" style="width: 23pt; mso-width-source: userset; mso-width-alt: 1097;"> <col width="32" style="width: 24pt; mso-width-source: userset; mso-width-alt: 1170;"> <col width="69" style="width: 52pt; mso-width-source: userset; mso-width-alt: 2523;"> <col width="71" style="width: 53pt; mso-width-source: userset; mso-width-alt: 2596;" span="2"> <col width="56" style="width: 42pt; mso-width-source: userset; mso-width-alt: 2048;"> <col width="19" style="width: 14pt; mso-width-source: userset; mso-width-alt: 694;"> <col width="49" style="width: 37pt; mso-width-source: userset; mso-width-alt: 1792;"> <col width="19" style="width: 14pt; mso-width-source: userset; mso-width-alt: 694;"> <col width="41" style="width: 31pt; mso-width-source: userset; mso-width-alt: 1499;"> <tbody> </tbody>
I need TR line not the multi_skill line. I obviously cant just delete the multi_skill line. I need this for some other agents. What am I doing wrong in the formula below?

For My_ROWS = 1 To Range("A" & Rows.Count).End(xlUp).Row

If Range("A" & My_ROWS).Value = "" And Range("H" & My_ROWS).Value = "TR" Then _
or Range("H" & My_ROWS).Value = "TR" And Range("A" & My_ROWS + 1).Value = "TR" Then
Range("A" & My_ROWS).Copy Range("A" & My_ROWS + 1) and Rows(my_rows).delete
end if
Range("A" & My_ROWS - 1).Copy Range("A" & My_ROWS) and Rows(My_ROWS - 1).Delete

Next My_ROWS
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
just a quick check for you, unless I'm mistaken, you need

Rich (BB code):
If Range("A" & My_ROWS).Value = "" And Range("H" & My_ROWS).Value = "TR" Then _
or Range("H" & My_ROWS).Value = "TR" And Range("A" & My_ROWS + 1).Value = "TR" Then


this gone. You may try that, see if you have success
 
Upvote 0
OK, i would nest until you get your logic down. In the case above, your column "H" is always goign to have TR in it - and I don't see that in your data. (in fact, I don't really see any column "H" in the data).

SO - I would ask, can you not just check the two version for TR? ColA & ColA+1? Or is ColH on a different sheet?

This code is direct translation from yours, just replacing values with variables for readability.

Rich (BB code):
dim colA as string, colB as string, colH as string

For My_ROWS = 1 To Range("A" & Rows.Count).End(xlUp).Row

 colA = Range("A" & MY_ROWS).Value
 colB = Range("A" & MY_ROWS+1).Value
 colH = Range("H" & MY_ROWS).Value

  If colH ="TR" then
    if colA = "" then
      Range("A" & My_ROWS).Copy Range("A" & My_ROWS + 1) and Rows(my_rows).delete
    elseif colB = "TR"
      Range("A" & My_ROWS).Copy Range("A" & My_ROWS + 1) and Rows(my_rows).delete
    End if
  End If

  Range("A" & My_ROWS - 1).Copy Range("A" & My_ROWS) and Rows(My_ROWS - 1).Delete 

Next My_ROWS



Let me know if that works out a little better for you. If it does, we can un-nest some of these and try with the And/Or. Easiest for me when I hit a wall to break everything into bits and attack it that way.

-In re-reading this, I'm wondering if column A & H are backwards - Should you be checking for H+1 instead?
 
Last edited:
Upvote 0
OK, i would nest until you get your logic down. In the case above, your column "H" is always goign to have TR in it - and I don't see that in your data. (in fact, I don't really see any column "H" in the data).

SO - I would ask, can you not just check the two version for TR? ColA & ColA+1? Or is ColH on a different sheet?

This code is direct translation from yours, just replacing values with variables for readability.

Rich (BB code):
dim colA as string, colB as string, colH as string

For My_ROWS = 1 To Range("A" & Rows.Count).End(xlUp).Row

 colA = Range("A" & MY_ROWS).Value
 colB = Range("A" & MY_ROWS+1).Value
 colH = Range("H" & MY_ROWS).Value

  If colH ="TR" then
    if colA = "" then
      Range("A" & My_ROWS).Copy Range("A" & My_ROWS + 1) and Rows(my_rows).delete
    elseif colB = "TR"
      Range("A" & My_ROWS).Copy Range("A" & My_ROWS + 1) and Rows(my_rows).delete
    End if
  End If

  Range("A" & My_ROWS - 1).Copy Range("A" & My_ROWS) and Rows(My_ROWS - 1).Delete 

Next My_ROWS



Let me know if that works out a little better for you. If it does, we can un-nest some of these and try with the And/Or. Easiest for me when I hit a wall to break everything into bits and attack it that way.

-In re-reading this, I'm wondering if column A & H are backwards - Should you be checking for H+1 instead?

thx, i just posted a simplified version so you could see what the data I am looking for is. TR is not always there they vary. therefore I need something that will look for a TR and duplicate names then delete the row that doesn't have the TR.
 
Upvote 0

Forum statistics

Threads
1,214,793
Messages
6,121,617
Members
449,039
Latest member
Mbone Mathonsi

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