简体   繁体   中英

Excel copy values to next available cells in a range

I'm working on a spreadsheet and I can't find an answer close enough to what I'm looking for, and my VBA knowledge is fairly basic.

I have a spreadsheet to keep track of who is in what team, and I'd like to have a 'master list' and choose which team the employee is moving into from a drop down list in Column F. I'd like to then copy Cells C,D & E into the next available cell in the range designated for that team, for example Employee A was showing in the team list for Team1, but have now moved to Team2 so I'd like them to be removed from the range set for Team1 and moved to the next available cell in the range set for Team2 (and ideally resort the values in the range). The two sheets are named "Names" and "Teams List".

Is this even possible, especially for a basic understanding of VBA?

Regards,

Cr1kk0

If (say) cell A1 contains your dropdown list with values Team1 , Team2 etc, and there are corresponding ranges named Team1, Team2 etc, then:

Dim myRange as Range
Set myRange = Range(Range("A1").Value)

defines myRange to be the range selected by the current value of the dropdown.

To refer to individual cells within the range, use the Cells property, eg:

myRange.Cells(3, 1).Value = "Fred Bloggs"

which refers to the cell in the third row and first column of myRange.

To find a value within the range, use (eg):

pos = Application.WorksheetFunction.Match("Fred Bloggs", myRange, 0)

which returns the position within myRange of the cell whose contents exactly match "Fred Bloggs" (but an error if there is no such cell).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM