VBA to copy cells meeting a criteria, then transpose paste to another worksheet

Status
Not open for further replies.

MarkR3003

New Member
Joined
Aug 11, 2019
Messages
25
Hi,

Is there anyone who could help me as I dont know where to start with this one. I have over 200 survey results coming in from MS Forms on an excel sheet where I need to create a VBA macro to copy/paste special specific cells that meet a criteria from that sheet to another worksheet but with paste special/transpose. I am trying to create a flat data table from the MS Forms worksheet. I may have to run the macro for each time there is a "N" entered into column A signifying that this data row has not yet been copied to the Flat Data Table. Example data attached to support the request

Step 1:
Sheet = Survey Data
Find the row where column A = "N" (Note - there will only be one row that meets this criteria , for example row 5)
Copy cells B5:D5 from this row
Paste Values (B5:D5) into worksheet = "Flat Data" in the next available blank cells in columns A:C which would be A7:C11 in the example file (The data in columns D:F will be already populated as these are common to all survey results)

Step 2:
Sheet = Survey Data
Find the row where column A = "N" (Note - there will only be one row that meets this criteria , for example row 5)
Copy cells E5:I5 from this row
Paste Special / Transpose Values (E5:I5) into worksheet = "Flat Data" in the next available blank cells in column G which would be G7:G11

I'm open to any other methods to create a flat data table in one operation using all 200 results or after each survey result row is added to the Survey Data worksheet

Really appreciate any help you can give as I'm completely lost on this occasion

Thanks

1659110407333.png


1659110452657.png
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Try:
VBA Code:
Sub CopyCells()
    Application.ScreenUpdating = False
    Dim srcWS As Worksheet, desWS As Worksheet, fnd As Range
    Set srcWS = Sheets("Survey Data")
    Set desWS = Sheets("Flat Data")
    With srcWS
        Set fnd = .Range("A:A").Find("N", LookIn:=xlValues, lookat:=xlWhole)
        If Not fnd Is Nothing Then
            .Range("B" & fnd.Row).Resize(, 3).Copy desWS.Cells(desWS.Rows.Count, "A").End(xlUp).Offset(1).Resize(5)
            .Range("E" & fnd.Row).Resize(, 5).Copy
            desWS.Cells(desWS.Rows.Count, "G").End(xlUp).Offset(1).PasteSpecial Transpose:=True
        End If
    End With
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Try:
VBA Code:
Sub CopyCells()
    Application.ScreenUpdating = False
    Dim srcWS As Worksheet, desWS As Worksheet, fnd As Range
    Set srcWS = Sheets("Survey Data")
    Set desWS = Sheets("Flat Data")
    With srcWS
        Set fnd = .Range("A:A").Find("N", LookIn:=xlValues, lookat:=xlWhole)
        If Not fnd Is Nothing Then
            .Range("B" & fnd.Row).Resize(, 3).Copy desWS.Cells(desWS.Rows.Count, "A").End(xlUp).Offset(1).Resize(5)
            .Range("E" & fnd.Row).Resize(, 5).Copy
            desWS.Cells(desWS.Rows.Count, "G").End(xlUp).Offset(1).PasteSpecial Transpose:=True
        End If
    End With
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub
Hey Mumps

Fantastic! Perfect! I am so grateful to you

Thanks very much
 
Upvote 0
Mumps and MarkR3003,

Thank you both for the direction and the code.

The code is not working. I would like to have some more details.


Regards,

VM
 
Last edited by a moderator:
Upvote 0
Please explain what you want to do in this thread.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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