Finding Certain Values and Copying & Pasting Data - VBA

susingh

New Member
Joined
Dec 21, 2014
Messages
2
Hi all,

I have a report that gets updated monthly and as it stands, a significant amount of manual work is required to update it.

I want to create a macro that will run down the rows of column A and every time it lands on a value that matches a userform selection by a user (a listbox that contains months), it copies the previous rows data from column B:AG and pastes it in the row (once again columns B:AG) that corresponds to the user selection. In addition, I would like to copy and paste values into the previous row so that I can edit links without changing last months data.

The report contains multiple projects (tables of data that are sorted vertically) which is why I need a macro that continually runs through the rows in column A finding matching values and manipulating the corresponding data. Another hurdle is that the projects are separated by an empty row.

I am sort of a rookie when it comes to VBA but I do have about 4 months experience creating macros in a VBA class.

Any direction would be greatly appreciated!

Thanks in advance.

-Sunny
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Here is the code I'm working with so far:

Code:
Option Explicit
Public RowRef As String


Sub findrows()
    Dim cell As Range
    Dim myrows As String
    
    For Each cell In Worksheets("Detail").Range("A:A")
        If cell.Value = RowRef Then
            myrows = myrows & cell.EntireRow.Address & ","
        End If
    Next cell

    myrows = Left(myrows, Len(myrows) - 1)

    MsgBox myrows
End Sub

The MsgBox returns what I'm looking for but in the wrong format. The string returns a dollar sign in front of each row number and it duplicates each row number as well.

Additional details:
RowRef is equal to the listbox value selected in the user form.

Once I figure out why the dollar signs show up and why the row addresses get duplicated, I should be able to figure out the remainder of the code.

Thanks!

-Sunny
 
Upvote 0

Forum statistics

Threads
1,213,562
Messages
6,114,322
Members
448,564
Latest member
ED38

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