Error in Line

NeoSez

Board Regular
Joined
Aug 14, 2020
Messages
210
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
I was using this script and it was working just up until the other day. Nothing changed and it kept giving an error. Dates are exactly how it's supposed to be.
When I decode it, it highlights this line. No idea why. I'm a noob. Help? Thank you.

VBA Code:
b(cr(1), cr(0)) = Format(a(i, 1), "mm/dd/yyyy") & vbLf & Join(Application.Index(a, i, Array(2, 3, 4)), vbLf)

Full script provided by Peter_SSs

VBA Code:
Sub Rearrange()
  Dim a As Variant, b As Variant, cr As Variant
  Dim d As Object
  Dim i As Long, lr As Long

  Set d = CreateObject("Scripting.Dictionary")
  d.CompareMode = 1
  With Sheets("Sheet2")
    lr = .Range("B" & Rows.Count).End(xlUp).Row
    a = Application.Index(.Cells, Evaluate("row(2:" & lr & ")"), Array(5, 2, 4, 3))
  End With
  ReDim b(1 To UBound(a), 1 To UBound(a))
  For i = 1 To UBound(a)
    If Not d.exists(a(i, 3)) Then d(a(i, 3)) = d.Count + 1 & " 1"
    cr = Split(d(a(i, 3)))
    b(cr(1), cr(0)) = Format(a(i, 1), "mm/dd/yyyy") & vbLf & Join(Application.Index(a, i, Array(2, 3, 4)), vbLf)
    d(a(i, 3)) = cr(0) & " " & cr(1) + 1
  Next i
  With Sheets("Sheet1")
    With .Range("A2").Resize(UBound(a), d.Count)
      .WrapText = True
      .Value = b
      .Rows(0).Value = d.Keys
    End With
  End With
End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
So, I've been trying to remove the date format part and just concatenate the three cells into one.
How do I do that? I tried numerous times but it keeps hitting error messages.
Help revise this line or the whole script above to concatenate the three cells (no dates involved) into one cell. Thank you.
VBA Code:
b(cr(1), cr(0)) = Format(a(i, 1), "mm/dd/yyyy") & vbLf & Join(Application.Index(a, i, Array(2, 3, 4)), vbLf)
 
Upvote 0
it kept giving an error.
Always give the full error message please.

That is my code from this post. I just tested it again on the same sample data as that old thread and it worked. What sample data did you have in Sheet2 this time? Please post it.
 
Upvote 0
Always give the full error message please.

That is my code from this post. I just tested it again on the same sample data as that old thread and it worked. What sample data did you have in Sheet2 this time? Please post it.
Good day Peter.
Error is:
Runtime 13
Type mismatch

It's using the same data as before. I tested it on Excel 2010 and then Excel 2019. It was working fine and then it this error kept popping up.
Can we just omit the date format part and concatenate 3 cells instead? I now wish to use a different concatenate combo.
And, thank you again for the brilliant VBA code, Peter. Much appreciated.
 
Upvote 0
Can we just omit the date format part and concatenate 3 cells instead?
Sure
Rich (BB code):
b(cr(1), cr(0)) = Format(a(i, 1), "mm/dd/yyyy") & vbLf & Join(Application.Index(a, i, Array(2, 3, 4)), vbLf)
 
Upvote 0
Thanks Peter. Appreciate the assistance. I tried to delete that portion but didn't delete far enough. Will try it and deleting & vbLf &
 
Upvote 0

Forum statistics

Threads
1,214,812
Messages
6,121,702
Members
449,048
Latest member
81jamesacct

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