VBA Delete .Address and shift up

tinderbox22

Board Regular
Joined
Mar 9, 2010
Messages
56
Office Version
  1. 365
Platform
  1. Windows
Hi,

I'm attempting to find multiple instances of a specific text string and then delete and shift cells up. However, if I use the .UsedRange property, there are instances of that same string that I do not want to delete. Is there a way to specify a range rather than using .UsedRange, when finding a cell address? When trying this, I get errors.
My cheat solution is to take my desired range to another blank worksheet, which is not ideal but doable.
Thanks in advance.
 
There are couple of things that needs to be taken care of when working Worksheet_Change event lest you may end your code in an endless loop and then crashing Excel. I will cover that when I post a reply. :)
 
Upvote 0

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Actually, I was able to install the Add-in without issue. I will work with this later today and post. Thanks again for all the suggestions and help. I much prefer to try and fail as much as possible before asking for help, and I've spent a good bit of time with this worksheet.
 
Upvote 0
Okay, so Excel freezes when I attempt to capture the mini sheet with that Add-In. Sorry about that. So, I'll do my best with pasted images.

This workbook is essentially an Auction Team Fantasy Draft, where eight players bid on a randomly selected college basketball team for March Madness.
There are EIGHT "Players," 64 "Teams," and 64 "Picks" in this Draft.

1641586950153.png


The important cell above is the merged AE3 where it says "Donny." In that cell is a lookup (=XLOOKUP($AA$3,'V TEAMS'!$X$24:$X$143,'V TEAMS'!$W$24:$W$143)) that pulls from another sheet ("V Teams") based on the Pick # in Cell AA3. The spin button next to AA3 increments by one when clicked, and it's the next person's turn. We then draft teams in 'snake draft' order (1, 2, 3...8, 8, 7, 6...1, etc.). Since this is an "auction" format league, any player can bid on that team, so in theory, Donny may not pick USC. It may go to Player 2 or Player 7, whomever wants to bid the most. Once each player reaches EIGHT teams that they've bid on, they will no longer pick. My macro that we were discussing on this thread is supposed to find all instances of the maxed out player's name from the range "VTEAMS!$W$24:$W$143" and delete and shift up, so that this player will no longer show up in cell AE3. I can't, however, simply skip to the next Pick #, because someone will need to bid on that next team in succession. If we skip it, then we've skipped a team. So, I need to skip only the player's name, not the pick or the team.

1641587581987.png


The above image is on the same tab, located directly below the first image I pasted. Ignore the purple "RANDOM" section, as that is out of play here. But within the green "AUCTION" section (rows 23-30), this is where the team name that's currently being auctioned off will be placed once that player bids on the team (FYI, there is another set of these below with the remaining four players - irrelevant for what I need here). I've placed mock teams and bid amounts in Player One (Donny)'s green section (Column J, Rows 23-29), as though he has bid on those teams, in order to test this macro. Notice in cell J32 where it shows $2 remaining. This is the amount that Donny has to bid on his remaining team, once his final team shows up in cell AE3 above. I would then enter that team in cell B30 and $2 in J30. This would trigger a COUNT function on the V TEAMS tab to equal 8. This is when I want my automation to occur. Ideally, I would like for Donny's name to disappear from the list of players so that he is now skipped over.

1641587780879.png


The above image includes the V TEAMS tab range that I'm attempting to delete and shift up (W24:W143). Notice cell Z13. This is where Donny's "team count" is at SEVEN currently. Once this reaches EIGHT, my macro should be triggered, and all instances of Donny's name should be found in W24:W143, deleted, and those cells only, shifted up. X and Y need to remain as is. If this happens successfully, all other players move up one pick, and Donny is removed. This of course will happen with each player eventually throughout the draft.

So, referencing the Autofilter macro that you suggested, as I stated, this macro does what it needs to do, however, I'm having trouble figuring out how to initiate this macro once cell Z13 (in this 'Donny' example') reaches 8. Obviously, each of Z13:Z20 will need to initiate the macro for that player.
 
Upvote 0
I'm attempting to run this macro with the Worksheet_Change event, whenever those cell values = 8, and I'm thinking there may be a better way. It definitely doesn't run as it should. I'm also not super familiar with change events.
 
Upvote 0
So to reconfirm

1. Monitor Z13:Z20
2. If any of the cell turns 8 then take that players name from A1:A20 and delete that name from W24:W143. The rest of then names simply go up?

Quick question (Just reconfirming)

How is the value changing in Z13:Z20? Is it by clicking the spin button which in turn change cell AA3?
 
Upvote 0
So to reconfirm

1. Monitor Z13:Z20
2. If any of the cell turns 8 then take that players name from A1:A20 and delete that name from W24:W143. The rest of then names simply go up?

Quick question (Just reconfirming)

How is the value changing in Z13:Z20? Is it by clicking the spin button which in turn change cell AA3?
1. Yes
2. If any of the cell turns 8 then take that players name from A13:A20 and delete that name from W24:W143. The rest of then names simply go up.

The values in cells Z13:Z20 are a COUNTIF function, ultimately counting the dollars in the SCORES tab.

I would love for the Autofilter macro to read the name that "maxes out" and just have one macro versus eight of them referencing different cells.
 
Upvote 0
I'm attempting to run the Worksheet_Change event for all eight players, using the final Auction cell for each of the players. I call my PlayerNameSKIP macro (autofilter macro), and it runs the macro properly. However, it bugs out with a run-time error message: "Application-defined or object-defined error." The debug highlights the "Set PlayerName = Target.offset(-16,-8)" line in the code below. Trying to figure out why it goes back to the Worksheet_Change event after ending the PlayerNameSKIP sub. Is there a way to only run this change event once? It should only run again when any of those intersect ranges are edited.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Answer As Integer

Set PlayerName = Target.Offset(-16, -8)

    If Not Intersect(Target, Range("J30, U30, AF30, AQ30, J52, U52, AF52, AQ52")) Is Nothing Then 'Skip Player
        Answer = MsgBox("Skip " & PlayerName, vbYesNo)
        If Answer = vbYes Then
            PlayerNameSKIP
        Else
            
        End If
    End If
    
End Sub
 
Upvote 0
How is the value changing in Z13:Z20? Is it by clicking the spin button which in turn change cell AA3?

The values in cells Z13:Z20 are a COUNTIF function, ultimately counting the dollars in the SCORES tab.

Is the Countif formula dependant on cell AA3? What is the formula?

Possible to see your file?
 
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,572
Members
448,972
Latest member
Shantanu2024

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