VBA code - copy, paste and delete on entire sheet

Vishaal

Well-known Member
Joined
Mar 16, 2019
Messages
543
Office Version
  1. 2010
  2. 2007
Platform
  1. Windows
  2. Web
help please,

We have the following data where in data sheet we have multiple entry, we have also recored a macro and want to it will run in whole sheet, help please

we are copying the data Sheet1!C3:C6 and pasting as transpose on Sheet1!C2 and after that copying the Sheet1!G6 to Sheet1!G2 and after this deleting the row 2 to 6, we required to do it in whole sheet

Data Sheet
Ajay Bhai T.xlsx
ABCDEFG
1NumberQueOption AOption BOption COption DAnswer
2286Solow’s paradox deals with the
3(A)Technology and labour
4(B)Labour and capital
5(C)Technology and productivity
6(D)Capital and productivityC
7287Bond holder always suffer a capital
8(A)Discount, hold to maturity
9(B)Discount, sell before maturity
10(C)Premium, hold to maturity
11(D)Premium, sell before maturityd
Sheet1


Result Sheet
Ajay Bhai T.xlsx
ABCDEFG
1NumberQueOption AOption BOption COption DAnswer
2286Solow’s paradox deals with theTechnology and labourLabour and capitalTechnology and productivityCapital and productivityC
3287Bond holder always suffer a capitalDiscount, hold to maturityDiscount, sell before maturityPremium, hold to maturityPremium, sell before maturityd
Sheet2


macro
Rich (BB code):
Sub Macro2()
'
' Macro2 Macro
'

'
    ActiveCell.Offset(-6, -3).Range("A1:A4").Select
    Selection.Copy
    ActiveCell.Offset(-1, 0).Range("A1").Select
    Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
    ActiveCell.Offset(4, 4).Range("A1").Select
    Application.CutCopyMode = False
    Selection.Copy
    ActiveCell.Offset(-4, 0).Range("A1").Select
    ActiveSheet.Paste
    ActiveCell.Offset(1, 0).Rows("1:4").EntireRow.Select
    Application.CutCopyMode = False
    Selection.Delete Shift:=xlUp
    ActiveCell.Offset(-1, 2).Range("A1").Select
End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Try:
VBA Code:
Sub TransposeData()
    Application.ScreenUpdating = False
    Dim lRow As Long, fRow As Long, LastRow As Long
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    With Range("C3:C" & LastRow).SpecialCells(xlCellTypeConstants)
        For i = .Areas.Count To 1 Step -1
            fRow = .Areas(i).Cells(1).Row
            lRow = .Areas(i).Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
            Range("C" & fRow - 1).Resize(, 4) = Application.Transpose(Range("C" & fRow & ":C" & lRow))
            Range("G" & fRow - 1) = Range("G" & lRow)
            Rows(fRow & ":" & lRow).Delete
        Next i
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 1
Solution

Forum statistics

Threads
1,224,812
Messages
6,181,088
Members
453,021
Latest member
Justyna P

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