MsgBox Error

jreed5535

New Member
Joined
Jul 25, 2020
Messages
15
Office Version
  1. 365
Platform
  1. Windows
Hi Guys,

I have the below error show up when i try and run my macro in File1 but works fine if i copy and paste the same code into file2.
1595988608802.png



The only difference is the MsgBox goes into capitals
1595988719903.png


1595988788418.png


any ideas why this is happening?

Cheers
 
Works perfect, thank you!

Now how would i copy and pate into that new inserted row?
 
Upvote 0

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
copy and paste what ??
and from where?
 
Upvote 0
Do you mean
VBA Code:
cells(r,4).Copy cells(r+2,4)
 
Upvote 0
Like this ??
VBA Code:
Sub MM1()
Dim r As Long, ws As Long
Set ws = Sheets("Sheet1")
For r = 2 To Cells(Rows.Count, "D").End(xlUp).Row
If Cells(r, 4).Value = ws.Cells(2, 4).Value Then   Cells(r + 2, 4).EntireRow.Insert
Next r
End Sub


How do i only get this to run once? instead of Next
 
Upvote 0
You mean run until the line is found then exit ??
Try
VBA Code:
For r = 2 To Cells(Rows.Count, "D").End(xlUp).Row
If Cells(r, 4).Value = ws.Cells(2, 4).Value Then 
Cells(r + 2, 4).EntireRow.Insert
exit For
end if
Next r
 
Upvote 0
Hmm, it gives me an error with the End If "End if without block if".
 
Upvote 0
This the full code from post #25....works fine for me !
VBA Code:
Sub MM1()
Dim r As Long, ws As Worksheet
Set ws = Sheets("Sheet1")
For r = 2 To Cells(Rows.Count, "D").End(xlUp).Row
If Cells(r, 4).Value = ws.Cells(2, 4).Value Then
Cells(r + 2, 4).EntireRow.Insert
Exit For
End If
Next r
End Sub
 
Upvote 0
Not sure what happened, working for me now too!

Have the file working perfectly now, thank you very much for all your help Michael!

Greatly appreciated!
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,394
Members
448,957
Latest member
Hat4Life

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