View Single Post
 
Old 05-17-2015, 12:04 AM
excelledsoftware excelledsoftware is offline Windows 8 Office 2003
IT Specialist
 
Join Date: Jan 2012
Location: Utah
Posts: 455
excelledsoftware will become famous soon enough
Default

Yup pretty easy. You can put this bit of code in the same module. The variable called ManipRows will allow you to put in any amount of manipulations you want. If it were me I would then put an autoshape on the same sheet where I copy and paste the new data and assign the FormatManipulationSheet code to it. That way when you copy and paste your new data you can just press the button and then everything will be ran. As always save the book before running.
Code:
Sub FormatManipulationSheet()
  'Writes in the data from a worksheet and formats in a way to use the algorithm
  
  Dim CheckRow As Long, ResultRow As Long, wb As Workbook, cws As Worksheet, rws As Worksheet
  Dim LastRow As Long, ManipRows As Integer, Col As Integer, LastCol As Integer, Mrow As Long
  Dim Mcount As Integer
  
  'Set the amount of Manipulation Rows
  ManipRows = 2
  
  'Set the references
  Set wb = ThisWorkbook
  Set cws = wb.Worksheets(1)
  Set rws = wb.Worksheets(2)
  ResultRow = 2
  LastRow = cws.Range("B2").End(xlDown).Row
  LastCol = cws.Range("B2").End(xlToRight).Column
  
  'Set up the headers
  For Col = 2 To LastCol
    rws.Cells(1, Col).Value = cws.Cells(1, Col).Value
  Next Col
  
  
  For CheckRow = 2 To LastRow
    For Col = 2 To LastCol
      rws.Cells(ResultRow, Col).Value = cws.Cells(CheckRow, Col).Value
    Next Col
    Mcount = 1
    For Mrow = ResultRow + 1 To ResultRow + ManipRows
      rws.Range("A" & Mrow).Value = "Manipulation " & Mcount
      Mcount = Mcount + 1
    Next Mrow
    ResultRow = ResultRow + ManipRows + 1
  Next CheckRow
  
  'If you want to have the other code run right after
  'just uncomment the 2 lines below.
  
  'rws.Activate
  'ManipulationAlg
  
End Sub
Let me know if you have any questions or concerns.

Thanks
Reply With Quote