Hi mdmackillop, I replicate this model in a new case with more provinces and columns. The ListBox2 does not work well. There is something wrong. Could you help to explain the part which I did wrongly.
The other thing is what if the contents of province is long, e.g. a short paragraph.
I am also attaching the excel here. THANKS! !
Sub Test() Dim LB1 As MSForms.ListBox
Dim LB2 As MSForms.ListBox
Set LB1 = ActiveSheet.ListBox1
Set LB2 = ActiveSheet.ListBox2
LB1.Clear: LB2.Clear
For Each shp In ActiveSheet.Shapes.Range(Array("group 3")).GroupItems
If Left(shp.Name, 4) <> "Free" Then
LB1.AddItem (shp.Name)
End If
Next
LB2.List = Array("Intro", "Manager", "Sales", "Budget", "Difference", "Pic")
LB2.Selected(3) = True
End Sub
Private Sub ListBox1_Click()
Application.ScreenUpdating = False
Set r = Selection
Reset
DoColor ListBox1
DoInfo ListBox1
DoEvents
r.Select
Application.ScreenUpdating = True
End Sub
Private Sub ListBox2_Change()
ListBox1_Click
End Sub
Sub DoInfo(State)
Dim wsD As Worksheet
If Not State = "" Then
Set wsD = Sheets("data")
Set Target = Range("P4")
Target.Resize(8, 18).ClearContents
For Each Shape In ActiveSheet.Shapes
If Shape.TopLeftCell.Address = "$P$4" Then Shape.Delete
Next
With ListBox2
For i = 0 To 5
If .Selected(i) Then
Select Case .List(i)
Case "Pic"
wsD.Shapes("Pic" & State).Copy
ActiveSheet.Paste Target
Case Else
Set dat = wsD.Columns(2).Cells.Find(State)
k = k + 1
Cells(16, 16).Offset(k) = .List(i)
Cells(16, 18).Offset(k) = dat.Offset(, i + 1)
End Select
End If
Next i
End With
End If
End Sub
Sub DoColor(State)
If Not State = "" Then
With ActiveSheet.Shapes.Range(Array(State)).Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 176, 80)
.Transparency = 0
.Solid
End With
End If
End Sub
Sub Reset()
With ActiveSheet.Shapes.Range(Array("Anhui", "Hebei", "Henan", "Heilongjiang", "Hubei", "Jilin", "Jiangsu", "Liaoning", "Shanxi", "Gansu", "Ningxia", "Sichuan", "Chongqing", "Xinjiang", "Fujian", "Guangdong", "Guangxi", "Hainan", "Jiangxi", "Yunnan", "Guizhou", "Zhejiang", "Hunan", "Shandong")).Fill
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorBackground1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = -0.0500000007
.Transparency = 0
.Solid
End With
End Sub