VBA Syntax Help

quickc2

New Member
Joined
Jun 20, 2017
Messages
22
Right now, I have a working VBA that allows me to input something into my first Text Box TB1 and it will change what is in cell A2 on the current worksheet. Then, based on what is inputted, the rest of my text boxes will then change what is in cells B2-Y2. The other text boxes in my VBA form display what are in the cells B2-Y2 where TB2(text box 2) displays B2, TB3(text box 3) displays C2 etc. Right now, I am having the issue with my code where if the Excel workbook is not in the correct worksheet that I want it in, the VBA will change what is in cell A2 of whichever worksheet I'm in rather than changing whats in cell A2 of Sheet2 like I want it. I would love help with the syntax of how I get that done.

Thanks,

Here is the code in my VBA Userform

Code:
Private Sub Image1_Click()


End Sub


Private Sub Label11_Click()


End Sub


Private Sub Label53_Click()
 
    Link = TB24.Text
    On Error GoTo NoCanDo
    ActiveWorkbook.FollowHyperlink Address:=Link, NewWindow:=True
    Exit Sub
NoCanDo:
    MsgBox "Cannot open" & Link
 
End Sub


Private Sub TB1_AfterUpdate()
    
    Dim I As Integer
    
    For I = 2 To 17
   
    
        Me.Controls("TB" & I).Text = Cells(2, I).Text
      
        
    Next I
        
        For k = 22 To 25
         
         Me.Controls("TB" & k).Text = Cells(2, k).Text
    
    Next k


End Sub






Private Sub TB2_Change()


End Sub


Private Sub TB22_Change()


End Sub


Private Sub TB23_Change()


End Sub


Private Sub TB24_Change()


End Sub


Private Sub TB3_Change()


End Sub


Private Sub TB4_Change()


End Sub


Private Sub UserForm_Initialize()
    
    Me.TB1.ControlSource = Cells(2, 1).Address


End Sub


Private Sub CommandButton1_Click()


Unload Me


End Sub
Private Sub UserForm_Activate()
With Application
    Me.Top = .Top
    Me.Left = .Left
    Me.Height = .Height
    Me.Width = .Width
End With
End Sub
 
Last edited by a moderator:

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Simply add the sheet name, like
Code:
Private Sub TB1_AfterUpdate()
    
    Dim I As Integer
    
    For I = 2 To 17
   
    
        Me.Controls("TB" & I).Text = Sheets("Data").Cells(2, I).Text
      
        
    Next I
        
        For k = 22 To 25
         
         Me.Controls("TB" & k).Text = Sheets("Data").Cells(2, k).Text
    
    Next k


End Sub
 
Upvote 0
Thanks for the help! That fixed the issue to where now all of the TextBoxes show the right values on Sheet2 that I wanted. However, it didn't fix the issue of when I change what's in Text Box 1 (TB1), it still changes cell A2 in whatever sheet is selected instead of always changing cell A2 in Sheet2.

If you have any ideas let me know
 
Upvote 0
Did you add the sheet name in the initialize event?
 
Upvote 0
You'll also need to set the address arguments
Code:
Sheets("Data").Range("A2").Address(external:=True)
 
Upvote 0
Have you linked TB1, or any other control, to a cell?
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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