Link to home
Create AccountLog in
Avatar of AaronBanker
AaronBanker

asked on

Public Sub, Empty Cell

I have many textboxes to change data.  the first Sub below was working, but with a few hundred textboxes this code slowed down the program.  So I made a public sum, as seen below, but i kept getting the value of c = "Empty"  

what am i doing wrong?

Private Sub TextBox1_Change()
   
     If wsMenu.Cells(12, 3).Value = "081" Then wsRoll.Cells(2, 7) = TextBox1.Value
     If wsMenu.Cells(12, 3).Value = "082" Then wsRoll.Cells(494, 7) = TextBox1.Value
     If wsMenu.Cells(12, 3).Value = "083" Then wsRoll.Cells(986, 7) = TextBox1.Value
     If wsMenu.Cells(12, 3).Value = "084" Then wsRoll.Cells(1478, 7) = TextBox1.Value
     If wsMenu.Cells(12, 3).Value = "085" Then wsRoll.Cells(1970, 7) = TextBox1.Value
     If wsMenu.Cells(12, 3).Value = "086" Then wsRoll.Cells(2462, 7) = TextBox1.Value
     If wsMenu.Cells(12, 3).Value = "087" Then wsRoll.Cells(2954, 7) = TextBox1.Value
     If wsMenu.Cells(12, 3).Value = "099" Then wsRoll.Cells(3446, 7) = TextBox1.Value
    
End Sub

Open in new window

_____________________________________________


Public Sub CellLocation()

    Dim c As Integer
    
     If wsMenu.Cells(12, 3).Value = "081" Then c = 2
     If wsMenu.Cells(12, 3).Value = "082" Then c = 494
     If wsMenu.Cells(12, 3).Value = "083" Then c = 986
     If wsMenu.Cells(12, 3).Value = "084" Then c = 1478
     If wsMenu.Cells(12, 3).Value = "085" Then c = 1970
     If wsMenu.Cells(12, 3).Value = "086" Then c = 2462
     If wsMenu.Cells(12, 3).Value = "087" Then c = 2954
     If wsMenu.Cells(12, 3).Value = "099" Then c = 3446

End Sub

Open in new window

Private Sub TextBox1_Change()
     CellLocation
     wsRoll.Cells(c, 7).Value = TextBox1.Value
UpdateSheet
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of AaronBanker
AaronBanker

ASKER

GrahamSkan:  I have no idea what "Code snippets in the question are now in code boxes." means
Qlemo:

would the next textbox be


Private Sub TextBox2_Change()
  wsRoll.Cells(CellLocation()+1, 7).Value = TextBox1.Value
  UpdateSheet
End Sub

Private Sub TextBox2_Change()
  wsRoll.Cells(CellLocation()+2, 7).Value = TextBox1.Value
  UpdateSheet
End Sub
I cannot tell whether your code is correct for what you are after, but syntactically it would work that way - if you name the subs correctly (the last sub needs to be TextBox3_Change()). And I suppose you want to change Textbox1.value to the respective one.
this doesn't seem to work