Next without For

skull_eagle

Board Regular
Joined
Mar 25, 2011
Messages
89
Hi,

I can't get the below code to work, not sure if I need to put some else statements or what.

Thank you


VBA Code:
For j = 2 To LastR
 
 If Cells(j, 13).Value = "X" Then
 HRWv1 = "WP "
 If Cells(j, 14).Value = "X" Then
 HRWv2 = "DG "
 If Cells(j, 15).Value = "X" Then
 HRWv3 = "RB "
 If Cells(j, 16).Value = "X" Then
 HRWv4 = "RI "
 If Cells(j, 17).Value = "X" Then
 HRWv5 = "RA "
  If Cells(j, 18).Value = "X" Then
 HRWv6 = "SB "
  If Cells(j, 19).Value = "X" Then
 HRWv7 = "SI "
  If Cells(i, 20).Value = "X" Then
 HRWv8 = "SA "
  If Cells(j, 21).Value = "X" Then
 HRWv9 = "LF "
  If Cells(j, 22).Value = "X" Then
 HRWv10 = "LO "
  If Cells(j, 23).Value = "X" Then
 HRWv11 = "CN "
 
 
 Cells(j, 24).Value = HRWv1 & HRWv2 & HRWv3 & HRWv4 & HRWv5 & HRWv6 & HRWv7 & HRWv8 & HRWv9 & HRWv10 & HRWv11


Next j
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
What about like this?

VBA Code:
For j = 2 To LastR
 
If Cells(j, 13).Value = "X" Then HRWv1 = "WP "
If Cells(j, 14).Value = "X" Then HRWv2 = "DG "
If Cells(j, 15).Value = "X" Then HRWv3 = "RB "
If Cells(j, 16).Value = "X" Then HRWv4 = "RI "
If Cells(j, 17).Value = "X" Then HRWv5 = "RA "
If Cells(j, 18).Value = "X" Then HRWv6 = "SB "
If Cells(j, 19).Value = "X" Then HRWv7 = "SI "
If Cells(i, 20).Value = "X" Then HRWv8 = "SA "
If Cells(j, 21).Value = "X" Then HRWv9 = "LF "
If Cells(j, 22).Value = "X" Then HRWv10 = "LO "
If Cells(j, 23).Value = "X" Then HRWv11 = "CN "

Cells(j, 24).Value = HRWv1 & HRWv2 & HRWv3 & HRWv4 & HRWv5 & HRWv6 & HRWv7 & HRWv8 & HRWv9 & HRWv10 & HRWv11

Next j
 
Upvote 0
Solution
What about like this?

VBA Code:
For j = 2 To LastR
 
If Cells(j, 13).Value = "X" Then HRWv1 = "WP "
If Cells(j, 14).Value = "X" Then HRWv2 = "DG "
If Cells(j, 15).Value = "X" Then HRWv3 = "RB "
If Cells(j, 16).Value = "X" Then HRWv4 = "RI "
If Cells(j, 17).Value = "X" Then HRWv5 = "RA "
If Cells(j, 18).Value = "X" Then HRWv6 = "SB "
If Cells(j, 19).Value = "X" Then HRWv7 = "SI "
If Cells(i, 20).Value = "X" Then HRWv8 = "SA "
If Cells(j, 21).Value = "X" Then HRWv9 = "LF "
If Cells(j, 22).Value = "X" Then HRWv10 = "LO "
If Cells(j, 23).Value = "X" Then HRWv11 = "CN "

Cells(j, 24).Value = HRWv1 & HRWv2 & HRWv3 & HRWv4 & HRWv5 & HRWv6 & HRWv7 & HRWv8 & HRWv9 & HRWv10 & HRWv11

Next j


Thank you so much, works perfectly.
 
Upvote 0

Forum statistics

Threads
1,215,193
Messages
6,123,566
Members
449,108
Latest member
rache47

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