VBA - Tabbing Data Pages Example

mrfantastic

New Member
Joined
Oct 23, 2018
Messages
2
Hello all:

Although I have been using Excel for many years, I am a relative novice to VBA, and am very new to Mr. Excel (my membership tenure is easily measurable in minutes). In any case, I am using a beginner-level VBA book to try to learn, but am stumped at one point (and I think the book may be wrong). In any case, the code I am on is meant to use a TabStrip control in a userform to manipulate worksheet data. Here’s the code I have right now…

Code:
Option Explicit
 
Sub Populate()
 
Select Case tabPrf.SelectedItem.Index
Case 0
txtTgt.Value = Range("B2").Value
txtSls.Value = Range("B3").Value
Case 1
txtTgt.Value = Range("C2").Value
txtSls.Value = Range("C3").Value
End Select
lblPct.Caption = Format(txtSls.Value / txtTgt.Value, "0%")
 
End Sub
 
 
Private Sub Label1_Click()
 
End Sub
 
Private Sub UserForm_Initialize()
 
tabPrf.TabStrip1(0).Caption = Range("B1").Value
tabPrf.TabStrip1(1).Caption = Range("C1").Value
'tabPrf.Tabs(0).Caption = Range("B1").Value
'tabPrf.Tabs(1).Caption = Range("C1").Value
 
End Sub
 
Private Sub tabPrf_Change()
 
Populate
 
End Sub
 
Private Sub cmdUpdate_Click()
 
 
Select Case tabPrf.SelectedItemIndex
Case 0
Range("B2").Value = txtTgt.Value
Range("B3").Value = txtSls.Value
Case 1
Range("C2").Value = txtTgt.Value
Range("C3").Value = txtSls.Value
End Select
lblPct.Caption = Format(txtSls.Value / txtTgt.Value, "0%")
 
End Sub


The code stops with the cmdUpdate sub at the Select Case line (apparently the SelectedItemIndex method is invalid). In any case, please help me troubleshoot (preferably with a simple fix or fixes if possible). Thank you very much.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Appreciate the response, but adding the period didn't solve the problem. When I tried to run, it stops, and .SelectedItem is flagged as an item not found. Thanks in advance for any other help.
 
Upvote 0

Forum statistics

Threads
1,214,912
Messages
6,122,204
Members
449,072
Latest member
DW Draft

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