Slow two values in dropdown list

Vincent88

Active Member
Joined
Mar 5, 2021
Messages
382
Office Version
  1. 2019
Platform
  1. Windows
  2. Mobile
Hi All,
Is it possible to have the dropdown list box to show values of 2 columns (G and H) from the table range.
The code that I currently use only shown column G. How to modify it ?

VBA Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

If Sh.Name = "Data" Then Exit Sub


Dim rngG As Range
Dim lr1 As Long, lrg As Long


'Range to apply Data Validation
lr1 = Range("A3").End(xlDown).Row
Set rngG = Range("C3:AL" & lr1)

'List in Sheet("Data")
Dim strG As String, strGH As String
lrg = Sheets("Data").Range("G1").End(xlDown).Row
strG = "='Data'!$G$2:$G" & lrg



'On Error Resume Next

If Target.CountLarge > 1 Then Exit Sub

If Not Intersect(Target, rngG) Is Nothing Then

With Target.Validation

 .Delete
 .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
  Operator:=xlBetween, Formula1:=strG             
 .IgnoreBlank = True
 .InCellDropdown = True
 .InputTitle = ""
 .ErrorTitle = ""
 .InputMessage = ""
 .ErrorMessage = ""
 .ShowInput = True
 .ShowError = True
End With

End If

End Sub
 

Attachments

  • shiftcol.png
    shiftcol.png
    21.1 KB · Views: 10

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Only with an activeX listbox.
 
Upvote 0
Why not use a helper column that joins the two columns?
 
Upvote 0
Hi Akuini,
How about to create a string or array to do the job without adding helper column ?
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

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