VBA Help - Have code apply to specific cell range

surkdidat

Well-known Member
Joined
Oct 1, 2011
Messages
594
Office Version
  1. 365
Good afternoon

I have the following code which presently populates any value put in column B down a certain amount of lines, however, I need this only to apply to a certain range (from B75 to B1500)

Can I ask what I need to amend to apply to only a certain cell range please?

Also, I have a Macro (currently called Button9_Click ) that is currently affected by this, and comes up with a RunTime Error 13 - Type Mismatch) - this code worked perfectly fine before the below code was added to the worksheet - again can anyone advise the best way around this please?


(Code for the above:-

If Target.Count = 1 And Target.Column = 2 And Target <> "" Then
Application.EnableEvents = False
Range(Target.Offset(1, 0), Target.Offset(13, 0)) = Target
Application.EnableEvents = True

End If
 
Thank you for that!!
When posting code please use code tags rather than quotes. It's the # icon in the reply window.
For your event code (assuming it's a worksheet_change event) try
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("B75:B1500")) Is Nothing Or Target.CountLarge > 1 Then Exit Sub
    If Target <> "" Then
        Application.EnableEvents = False
        Range(Target.Offset(1, 0), Target.Offset(13, 0)) = Target
        Application.EnableEvents = True
    End If
End Sub
And for your button code add these 2 lines one at the very top & the other at the bottom.
Code:
        Application.EnableEvents = False
        Application.EnableEvents = True
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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