excel vba

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Excel VBA

Excel VBA

resolvedResolved · Medium Priority · Version 2016

Excel VBA

Hi,


My code currently matches the value (Text) of a cell in a sheet to a cell in another sheet containing the same word. The code then copies the full range of data in that row to a third sheet.

The sheets are as follows :
Data Sheet - this is a sheet with all of my information
Data Input - the user selects a name from a drop-down list
Sheet3 - this is a sheet to deposit the copied data from "Data Sheet"


The two issues I have are,
Firstly : I need to be able to put names in any order in "Data Input" and have the corresponding data from "Data Sheet" copied and pasted into the order that is in "Data Input".
i.e. name 1
name 4
name 2
Title
name 3
At the moment the data in "Data Sheet" is in alphabetical order and so my results are in alphabetical order, I want to be able to be flexible in the order

Secondly:
I need to be able to input and copy duplicate names.
i.e. as of now if my name is Unit 1. If this is input into "Data Input" the code will only copy/paste one row. Whereas I would want to have two rows of "Unit 1"

See code below.
Best regards
Liam


Dim c As Range, d As Range, e As Range
Application.ScreenUpdating = False

Worksheets("Sheet3").Range("A1:HA1000").ClearContents

Worksheets("Data Sheet").Activate
For Each c In Range("B13:B300")
For Each d In Worksheets("Data Input").Range("B13:B300")

If d = c Then
Application.CutCopyMode = False
c.Resize(1, 210).Copy
Worksheets("Sheet3").Range("B65536").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Exit For
End If
Next
Next


Worksheets("Data Input").Range("B13:DM300").Value = Worksheets("Sheet3").Range("B2:DM300").Value

Worksheets("Data Input").Range("DP13:HA300").Value = Worksheets("Sheet3").Range("DP2:HA300").Value
Worksheets("Data Input").Range("U12:U300").ClearContents

Worksheets("Data Input").Activate
Range("B12").Select


Application.ScreenUpdating = True


End Sub



RE: Excel VBA

Hi Liam,

Thank you for the forum question.

I have attached a workbook where you can find a way of doing it. Well there is two different solutions. One can find one name another can find many names.

Can I give you an advice. Never copy and Paste in VBA. Copy and Paste is not a good solution, You can get a lot of problems doing it.

I hope my examples can guide you in the right direction.


Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

Attached files...

forum.xlsm

Tue 27 Mar 2018: Automatically marked as resolved.

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Outlining - ungrouping rows or columns

Highlight want you want to ungroup and press ALT + SHIFT + right cursor arrow

View all Excel hints and tips


Server loaded in 0.08 secs.