VBA: Column headers how to make it work

montecarlo2012

Well-known Member
Joined
Jan 26, 2011
Messages
984
Office Version
  1. 2010
Platform
  1. Windows
Hi.
I make it work some simple and basic loop, the idea just add each row on column A and B and the total on C, for that I write the following code and work good.
VBA Code:
Sub g_one()
      Dim x As Long, y As Long
      
            For x = 1 To 4
                     For y = 1 To 2
                     
                              
                             Cells(x, "C").Value = Cells(x, "A").Value + Cells(x, "B").Value
                     
                     
                     Next y
            Next x
End Sub
for this little peace of data
1592960079708.png

Now, here is my problem, I just tried to keep the same logic I use for this one, just change the A, B and C for names, then do not work.
1592960197051.png

this is the code I use the same logic
VBA Code:
Sub Name_per_column()
      Dim x As Long, y As Long
      
      For x = 1 To 5
               For y = 6 To 7
               
                           Cells(x, "total").Value = Cells(x, "payment").Value * Cells(x, "hour").Value
                           
               Next y
      Next x

End Sub
So of course I am missing something here,
Please, I need some logic here, what I have to change to make it work,
Thanks for reading this.
<tbody>
20​
80​
100​
paymenthourstotal
30​
70​
100​
60​
40​
40​
60​
100​
70​
30​
50​
50​
100​
80​
20​
90​
10​
</tbody>
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
If you want to use header names for your column reference, it would have to be a table. Regular Excel does not recognize a string name as the column object.
 
Upvote 0

Forum statistics

Threads
1,214,402
Messages
6,119,301
Members
448,885
Latest member
LokiSonic

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