Select first item from a drop down menu list in VBA

Peter Davison

Active Member
Joined
Jun 4, 2020
Messages
435
Office Version
  1. 365
Platform
  1. Windows
I have a macro running and before it leaves the sheet it is on, I want it to select a cell (E3) which has a drop down menu (Range Name "List)" and then select the first item in the list.
Can you advise what the code would look like?
Thank you
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Copy and paste this macro into the worksheet code module. Do the following: right click the tab name for your sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet.
VBA Code:
Private Sub Worksheet_Deactivate()
    Range("E3") = Range("List").Cells(1, 1)
End Sub
 
Upvote 0
Copy and paste this macro into the worksheet code module. Do the following: right click the tab name for your sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet.
VBA Code:
Private Sub Worksheet_Deactivate()
    Range("E3") = Range("List").Cells(1, 1)
End Sub
Hello this was really helpful for me but I would need to go beyond that.
I would need to have similar code but were in the code the selection of the list items goes as a string to the next one.

I need to select the first time the first item from the list, copy, paste to a new sheet and save then come back to dropdown list and do the same with the next item of the list and this until the last item of the list.

So i'm assuming I need to create it so that the number in red below changes but don't know how to do that.
The number in red needs to increase +1 everytime from the previous one.

Range("C3") = Range("FabricCode").Cells(1, 1)

Would be great if you could help me too on that.
 
Upvote 0
I need to select the first time the first item from the list, copy, paste to a new sheet and save then come back to dropdown list and do the same with the next item of the list and this until the last item of the list.
Do you want to go through all the items in the drop down list when you select the first item only or will you be selecting each item in the list, one at a time. What is the name of the sheet and into which cell in that sheet do you want to paste the value? What exactly do you want to save and where do you want to save it? It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach a screenshot (not a picture) of your sheet. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
 
Upvote 0
May be this
VBA Code:
Private Sub Worksheet_Deactivate()
Dim T As Long
Application.EnableEvents = False
On Error Resume Next

For T = 1 To Range("List").Cells.Count
Sheets.Add After:=ActiveSheet
ActiveSheet.Range("C3") = Range("List").Cells(T, 1)
Next T
Application.EnableEvents = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,257
Members
449,075
Latest member
staticfluids

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