Guest User

Untitled

a guest
Oct 12th, 2021
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.48 KB | None | 0 0
  1. Sub import_comments_v2()
  2. Dim c As Range, comment As String, row As Long
  3.  
  4. If Sheet1.ListObjects.Count > 0 Then
  5.     Sheet1.ListObjects(1).Unlist 'converts table to a range
  6. End If
  7.  
  8. For Each c In Sheet2.Range(Sheet2.Range("b1"), Sheet2.Range("b9999").End(xlUp))
  9.     If c.Value <> "" Then
  10.         comment = c.Offset(0, 2).Value & ";" & c.Offset(0, 1).Value & ";" & VBA.Chr(34) & c.Value & VBA.Chr(34)
  11.         If c.Offset(0, -1).Value <> "" Then
  12.             If IsNumeric(VBA.Replace(c.Offset(0, -1).Value, "Row", "")) = False Then
  13.             Sheet2.Select
  14.             c.Offset(0, -1).Select
  15.             MsgBox "I can't succesfully extract the row number from this cell", vbExclamation, "This is it" 'checks if type mismatch is from the rows
  16.             Exit Sub
  17.             End If
  18.         row = VBA.Replace(c.Offset(0, -1).Value, "Row", "")
  19.         End If
  20.  
  21.         If Sheet1.Range("xfd" & row).End(xlToLeft).Column < 24 Then 'if it's before y it starts from y (column 24)
  22.         Sheet1.Cells(row, 24).Offset(0, 1).Value = comment
  23.         Sheet1.Cells(1, 25).Value = "Comments"
  24.         Else
  25.         Sheet1.Cells(row, Sheet1.Range("xfd" & row).End(xlToLeft).Column).Offset(0, 1).Value = comment
  26.         Sheet1.Cells(1, Sheet1.Range("xfd" & row).End(xlToLeft).Column).Value = "Comments"
  27.         End If
  28.  
  29.     End If
  30. Next c
  31. Sheet1.ListObjects.Add(xlSrcRange, Range("a1").CurrentRegion, , xlYes).Name = "Tasks" ' converts it back to a table
  32.  
  33. MsgBox "Comments imported!", vbInformation
  34.  
  35.  
  36. End Sub
Advertisement
Add Comment
Please, Sign In to add comment