VBA: Referencing every other column?

Peter h

Active Member
Joined
Dec 8, 2015
Messages
417
I can not seem to figure this out. I'm trying to make this code as simple as possible, without using loops or "If" statements, but cannot seem to figure out how to reference every odd numbered column. I've got a sheet that has a list of "Player's Names" in column A. I have headers going across each column alternating "Win", "Loss", "Win", "Loss", etc... The number of Win/Loss columns is determined by a number of matches entered into a TextBox in my UserForm. So if the number of matches entered in the textbox is 3 then I'd have 6 columns starting in "B", Win, Loss, so on and so forth. Then in my Userform, I've got a 2 listboxes. 1 has the list of players names, and the 2nd one has a list of how many matches there are (1, 2, 3, etc.). What I want to do is be able to select a player in the first listbox, and then select what match I'm updating in the 2nd listbox then enter the number of wins into a textbox and a number of losses in a 2nd textbox, and then when I click submit it should add the number of wins and losses to the corresponding columns on that player's row. So if I select the first player, and match 2, and enter 2 wins and 1 loss into the textboxes, it should update column 4 for the "Wins" entered and column 5 for the "Losses" entered.

This is what I've gotten so far, and it works for my "Win" columns, but can't seem to figure out how to reference the odd numbered columns.

Code:
Private Sub btn_Submit_Click()
Dim i As Integer
Dim j As Integer
i = Me.lb_Players.ListIndex + 1
j = Me.lb_Rounds.ListIndex + 1
ws.Cells(i + 1, j * 2) = Me.tb_Wins
End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Untested but how about
Code:
ws.Cells(i + 1, (j * 2)+1) = Me.tb_Wins
or
Code:
ws.Cells(i + 1, j * 2).offset(,1) = Me.tb_Wins
 
Upvote 0
Untested but how about
Code:
ws.Cells(i + 1, (j * 2)+1) = Me.tb_Wins
or
Code:
ws.Cells(i + 1, j * 2).offset(,1) = Me.tb_Wins

That's it.... I think it's time for some more coffee. My brain isn't functioning on even the most basic simple things... lol.
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,981
Messages
6,175,768
Members
452,668
Latest member
mrider123

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