mackemforever
New Member
- Joined
- Jun 29, 2020
- Messages
- 6
- Office Version
- 2019
- Platform
- Windows
I posted a similar thread to this yesterday so I do apologise, but having spent another few hours bashing my head against this problem and going over the suggestions I've still not managed to figure out a solution to this issue. So please explain to me like I'm 5!
So I have the incredibly clunky bit of code below achieving the task of creating a new sheet with the customers name on it, copying the new data, pasting it on the customer sheet, applying a bit of formatting, locating the next available row on the master sheet and pasting the info there then clearing the New Info sheet, and while it's a weird bodge of recorded macro code and suggestions from here it works.
Now for the problem.
On the New Info sheet I have an area for entering a new service. This takes the form of a drop-down menu which pulls the list of customer names from the Master sheet and a few cells to fill in.
Once I've filled in the relevant cells and selected the customer from the list I want the macro to copy the cells, switch to the sheet whose name matches the selected customer, and paste it, but I cannot for the life of me figure out how to switch to the correct sheet.
How would I switch to a sheet whose name matches the name I have selected?
Thanks.
So I have the incredibly clunky bit of code below achieving the task of creating a new sheet with the customers name on it, copying the new data, pasting it on the customer sheet, applying a bit of formatting, locating the next available row on the master sheet and pasting the info there then clearing the New Info sheet, and while it's a weird bodge of recorded macro code and suggestions from here it works.
VBA Code:
Range("A1:B4").Select
Selection.copy
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = Range("'New Info'!$B$1").Value
Range("A1").Select
ActiveSheet.Paste
Columns("A:A").EntireColumn.AutoFit
Columns("B:B").EntireColumn.AutoFit
Range("A1:A4").Select
Selection.Font.Bold = True
Sheets("New Info").Select
Range("B1:B4").Select
Selection.copy
Sheets("Master").Select
Range("A1").Select ' change A1 to the top cell of your destination
If ActiveCell.Offset(1, 0).Value <> "" Then Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:=True, Transpose:=True
Sheets("New Info").Select
Range("b1:b4").Select
Selection.ClearContents
Now for the problem.
On the New Info sheet I have an area for entering a new service. This takes the form of a drop-down menu which pulls the list of customer names from the Master sheet and a few cells to fill in.
Once I've filled in the relevant cells and selected the customer from the list I want the macro to copy the cells, switch to the sheet whose name matches the selected customer, and paste it, but I cannot for the life of me figure out how to switch to the correct sheet.
How would I switch to a sheet whose name matches the name I have selected?
Thanks.