how to loop over rows of cells

semidevil

New Member
Joined
Jul 9, 2007
Messages
35
Im trying to write a VBA code where it will copy and paste data from an excel sheet to a powerpoint table. Pasting data over to powerpoint table is fine. The issue is that I can't solve is I' trying to paste one cell at a time in each column(L6, M6 N6), and then move over to the next row and repeat(L7, M7, N7)

So for example, the first value to copy will be in Cell "L6." After L6 is copied, it'll copy M6, N6, O6, P6 etc etc. Once I'm done with Row 6 it should start over again at L7, M7, N7 O7, P7. etc.
I think nested loop is the answer, but I do not really know how to use it (the below eample is wrong I know.

Here's my attempt so far:

Code:
j = 0

    With ppslide.Shapes("table1")
For k = 0 To 4
    For i = 1 To 5
    .Select
    .Table.Cell(3, i).Shape.TextFrame.TextRange.Text = Format(ThisWorkbook.Sheets("ws").Range("L6").Offset(k, j).Value, "0.00"
    j = j + 1
    Next i
j = 0
j = j + 1
Next k

End With
End If
so to explain
this is what I want to happen if I were to code it line by line
Code:
table.cell(3,1) = Format(Thisworkbook.sheets("ws").Range("L6").Offset(0,0).value, "0.00")
table.cell(3,2) = Format(Thisworkbook.sheets("ws").Range("L6").Offset(0,1).value, "0.00")
table.cell(3,3) = Format(Thisworkbook.sheets("ws").Range("L6").Offset(0,2).value, "0.00")
table.cell(3,4) = Format(Thisworkbook.sheets("ws").Range("L6").Offset(0,3).value, "0.00")
table.cell(3,5) = Format(Thisworkbook.sheets("ws").Range("L6").Offset(0,4).value, "0.00")

table.cell(4,1) = Format(Thisworkbook.sheets("ws").Range("L6").Offset(1,0).value, "0.00")
table.cell(4,2) = Format(Thisworkbook.sheets("ws").Range("L6").Offset(1,1).value, "0.00")
table.cell(4,3) = Format(Thisworkbook.sheets("ws").Range("L6").Offset(1,2).value, "0.00")
table.cell(4,4) = Format(Thisworkbook.sheets("ws").Range("L6").Offset(1,3).value, "0.00")
table.cell(4,5) = Format(Thisworkbook.sheets("ws").Range("L6").Offset(1,4).value, "0.00")
table.cell(5,1) = Format(Thisworkbook.sheets("ws").Range("L6").Offset(2,0).value, "0.00")
table.cell(5,2) = Format(Thisworkbook.sheets("ws").Range("L6").Offset(2,1).value, "0.00")
table.cell(5,3) = Format(Thisworkbook.sheets("ws").Range("L6").Offset(2,2).value, "0.00")
table.cell(5,4) = Format(Thisworkbook.sheets("ws").Range("L6").Offset(2,3).value, "0.00")
table.cell(5,5) = Format(Thisworkbook.sheets("ws").Range("L6").Offset(2,4).value, "0.00")

etc
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Hello semidevil,

I had only one Power Point presentation open with this macro when I tested it. This worked fine for me.

NOTE: I changed the name of my Table to "Table1". Normally the default name has a space like this "Table 1". Be sure your Table name is correct.

Code:
Sub Test()


    Dim i   As Long
    Dim k   As Long
    Dim PPT As Object
    Dim Rng As Range
    Dim Tbl As Object
    Dim Wkb As Workbook
    
        Set PPT = GetObject(, "PowerPoint.Application")
        
        Set Wkb = ThisWorkbook
        Set Rng = Wkb.Worksheets("ws").Range("L6")
        
        Set Tbl = PPT.Presentations(1).Slides(1).Shapes("Table1").Table
        
        With Tbl
            For k = 1 To .Rows.Count
                For i = 1 To .Rows(k).Cells.Count
                   .Cell(k, i).Shape.TextFrame.TextRange.Text = Format(Rng.Offset(k - 1, i - 1).Value, "0.00")
                Next i
            Next k
        End With


End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,823
Messages
6,121,779
Members
449,049
Latest member
greyangel23

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