jdyce
jdyce

Reputation: 1

VBA spreadsheet. Adding new rows and copying a cell from that row to the row beneath

I am a complete beginner to excel VBA, and I have been consistently creating a report for work which consists of excel spreadsheet columns downloaded from salesforce. The Columns are (A) through (T) and Column (T) contains comments for each of the projects in that same row.

I have been inserting a new row beneath each project and dragging Column cell (T1) into that row, then merging and centering that row.

then I repeat the process for Row 3 (Originally Row 2) and take Column cell (T3) and insert a new Row below the Row 3 project and Drag (T3) below then merge and center that row.

this process repeats. ( I have only done this once for someone else manually before realizing it is ridiculous to do manually) I am quite stuck with writing a macro for this.

I know I need to:

  1. Set range as active sheet
  2. Initiate While Loop
  3. Insert new row
  4. Merge cells in row (x) Column A through T
  5. Copy (Column T, Row 1) to Row 2 , Column Cell (A-T)
  6. Delete (Column T, Row 1)
  7. shift down to the next (Column T, Row x) until nothing is left.
  8. Loop

End Sub

I know what I need to do. But I cannot think of the correct code to get me where I need to go.

Can anyone help with this?

Added below is the written code of what I have so far.

Aright here is what I have so far.It breaks and just continues merging that same row over and over (endless loop). I am guessing it has to do with ActiveSheet.Paste. Any Ideas for me?

Sub Addingrowsv1

Do Until ActiveCell.Value = ""
    Rows("3:3").Select
    Range("C3").Activate
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("T2").Select Selection.Copy 
    Range("C3").Select
    ActiveSheet.Paste
    Range("C3:S3").Merge
Loop
End Sub

Thank you, Jim

Upvotes: 0

Views: 466

Answers (1)

James Thomas
James Thomas

Reputation: 1

VBA is quite good at manipulating data; so what you want to do is well within VBA scope.

First, start by turning on the macro recorder and do one of your pairs of lines. They go look at the recorded code.

Generally, you will then take the recorded code and customize it to go inside a loop.

Do you need help in doing a recording?

Upvotes: 0

Related Questions