Archive for August, 2013
Sample VBA for looping thru rows and copying data
Posted by allenkwc in .net, Technology on August 16, 2013
Sub CopyData()
Dim iLastRow As Integer
Dim Rng As Range
iLastRow = Cells(Rows.Count, “K”).End(xlUp).Row
Dim ws1 As Worksheet
Set ws1 = Sheets(“Worksheet”)
Dim lastPo As String
Dim lastPoLine As String
Dim lastStyle As String
Dim lastDim As String
For i = 1 To iLastRow
‘handle style
If Not IsEmpty(ws1.Cells(i, “D”).Value) Then
lastStyle = ws1.Cells(i, “D”).Value
Else
ws1.Cells(i, “D”).Value = lastStyle
End If
‘handle values
If Not IsEmpty(ws1.Cells(i, “E”).Value) Then
lastPo = ws1.Cells(i, “E”).Value
lastPoLine = ws1.Cells(i, “F”).Value
lastDim = ws1.Cells(i, “G”).Value
Else
ws1.Cells(i, “E”).Value = lastPo
ws1.Cells(i, “F”).Value = lastPoLine
ws1.Cells(i, “G”).Value = lastDim
End If
Next i
End Sub