I've referenced this site to answer many of my questions, but this is one I couldn't find an answer to.
Public Sub RemoveBlanks()
Dim Table As ListObject
Set Table = Worksheets("Sheet1").ListObjects("ExampleTable")
Dim r As Range
With Table.DataBodyRange
For Each r In Table.DataBodyRange
If r.Value = "" Then r.Value = "-"
Next r
End With
End Sub
This is the code I used(changed variable/sheet names to generic for ease of conversation).
Declared the variable
Dim r As Range
But never set a reference or defined what r is.
So how does this part work? I thought that for each variable a value or reference had to be assigned for VBA to know what to do with it.
For Each r In Table.DataBodyRange
If r.Value = "" Then r.Value = "-"
Next r
I'm looking for the why.
This is my first post, and I am very green at this programmiing/coding business-Google has been my friend. I'm looking for more theory instead of the good old copy/paste the code in, make a few name changes, and cross my fingers.
My appologies if the formating isn't perfect. I'm happy to clarify if what I'm asking doesn't make sense.
For Each ris what performs the assignment - each cell inDatabodyRangeis sequentially assigned torlearn.microsoft.com/en-us/office/vba/language/reference/… FYI yourWithblock isn't doing anything here.For Each r In...bit sets thervariable to the cells in the table, one cell at a time.for i = 1 to 10that works a little differently than afor eachFor Each r In Table.DataBodyRange.Cellsto be more explicit about what the code is doing