Help to tidy up code

Chewyhairball

Active Member
Joined
Nov 30, 2017
Messages
312
Office Version
  1. 365
Platform
  1. Windows
Hi
I have the following code that converts the cell contents in the comments column in 3 different tables, when cell BH3 or BH4 changes. All the tables are on the same sheet.
What I have does work but I am guessing there would be a tidier, more efficient way to write this.
thanks
Rory

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("bh3:bh4")) Is Nothing Then
Range("Results1[[#Data],[Comments]]").Select
Call ConvertToComment

Range("Results2[[#Data],[Comments]]").Select
Call ConvertToComment

Range("Results230[[#Data],[Comments]]").Select
Call ConvertToComment

End If
End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
The key code is contained in the subroutine ConvertToComment, which you've not provided here. I don't see that there is much you can change here without potentially affecting the functionality of the other subroutine.
 
Upvote 0
Maybe:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim TableNames As Variant, t As Variant

    If Intersect(Target, Range("bh3:bh4")) Is Nothing Then Exit Sub

    TableNames = Array("Results1", "Results2", "Results230")
    For Each t In TableNames
        Range(t & "[[#Data],[Comments]]").Select
        Call ConvertToComment
    Next t

End Sub
 
Upvote 0
Thanks for the reply Eric. I will just stay with what I have got.

have a good day :)
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,841
Members
449,051
Latest member
excelquestion515

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