Solved

Macro for Excel: Find Cell that matches value of other cell and paste clipboard

Posted on 2001-07-12
2
224 Views
Last Modified: 2012-06-27
Hi there,

I've got an Excel-Workbook with several sheets and want to attach a macro with a button on one of them. The macro is supposed to copy a defined range Selection and paste it on another sheet in a cell on another sheet (DestCell). DestCell is on another sheet and shall be depending on the current date (found in DateCell). DestCell is located two collums right of a cell with matching content to DateCell.

I've got the copy and paste stuff covered, but I'm struggeling with activating DestCell, i.e. finding the matching cell for DateCell on the DestinationSheet.

Thanks, Chris
0
Comment
Question by:fizher
2 Comments
 
LVL 5

Accepted Solution

by:
Draak earned 200 total points
ID: 6279564
  Hi,

here is some code to search for a certain cell containing specific data and then activating this cell. Here I'm looking for the value 07/13/01 in a range I selected.

    'define a cell
    Dim aCell As Variant
   
    'Select the range
    Range("D9:D18").Select
   
    'Find the cell you are looking for
    'the data you are looking for should be between the quotes behind What:=
    Set aCell = Selection.Find(What:="07/13/01", After:=ActiveCell, LookIn:=xlValues, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False)
   
    'Select the cell if it has been found
    If Not aCell Is Nothing Then
        aCell.Select
    End If

You can easily replace the value to search for with the content of your destcell.

best regards

Draak
0
 

Author Comment

by:fizher
ID: 6281726
Hi Draak,

thanks for the code - that was basically what I had in my code before, but it showed me that it wasn't this part that didn't work. (I defined a string (MToaday) as Range("A1").Value instead of Range("A1").Text - so it wouldn't find it and the value didn't exist in the defined search range - so thanks again.

Best, Chris
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now