Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub import_comments_v2()
- Dim c As Range, comment As String, row As Long
- If Sheet1.ListObjects.Count > 0 Then
- Sheet1.ListObjects(1).Unlist 'converts table to a range
- End If
- For Each c In Sheet2.Range(Sheet2.Range("b1"), Sheet2.Range("b9999").End(xlUp))
- If c.Value <> "" Then
- comment = c.Offset(0, 2).Value & ";" & c.Offset(0, 1).Value & ";" & VBA.Chr(34) & c.Value & VBA.Chr(34)
- If c.Offset(0, -1).Value <> "" Then
- If IsNumeric(VBA.Replace(c.Offset(0, -1).Value, "Row", "")) = False Then
- Sheet2.Select
- c.Offset(0, -1).Select
- MsgBox "I can't succesfully extract the row number from this cell", vbExclamation, "This is it" 'checks if type mismatch is from the rows
- Exit Sub
- End If
- row = VBA.Replace(c.Offset(0, -1).Value, "Row", "")
- End If
- If Sheet1.Range("xfd" & row).End(xlToLeft).Column < 24 Then 'if it's before y it starts from y (column 24)
- Sheet1.Cells(row, 24).Offset(0, 1).Value = comment
- Sheet1.Cells(1, 25).Value = "Comments"
- Else
- Sheet1.Cells(row, Sheet1.Range("xfd" & row).End(xlToLeft).Column).Offset(0, 1).Value = comment
- Sheet1.Cells(1, Sheet1.Range("xfd" & row).End(xlToLeft).Column).Value = "Comments"
- End If
- End If
- Next c
- Sheet1.ListObjects.Add(xlSrcRange, Range("a1").CurrentRegion, , xlYes).Name = "Tasks" ' converts it back to a table
- MsgBox "Comments imported!", vbInformation
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment