Output error with VBA

ryan8200

Active Member
Joined
Aug 21, 2011
Messages
357
Based on the data and output at [FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]https://ibb.co/qNmx8Lz

What is the error that caused error at 3rd column of the output ?

Below is the code that I have been using

Code:
Sub MissingHobbies()
Dim c As Integer, h As Integer, ans As Integer
ans = 9
For c = 2 To 11    ' candidates
  For h = 3 To 6  ' hobbies
  Cells(8, 1) = "Hobbies"
  Cells(8, 2) = "Candidates"
  If Cells(h, c) = "N" Then
  Cells(ans, 1) = Cells(h, 1)
  Cells(ans, 2) = Cells(1, c)
  ans = ans + 1
  Else
End If
Next h
Next c
End
End
End Sub

Appreciate if fellow members can give me a helping hand.



[/FONT]
 
Last edited by a moderator:

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
I don't follow - there are only 2 columns of output in that code.
 
Upvote 0
And what is the error? I didn't see any error values in the picture.
 
Upvote 0
Looks like you have merged cells in row 1, so every other cell is technically blank.
 
Upvote 0
Instead of:

Code:
Cells(ans, 2) = Cells(1, c)

you could use:

Code:
If Cells(1, c).value = vbnullstring then
Cells(ans, 2) = Cells(1, c - 1).Value
else
Cells(ans, 2) = Cells(1, c).Value
end if
 
Upvote 0
Thanks for helping me. Do you mind share with me, how you master your VBA skills ?
I really not able to think of the solution.
 
Last edited by a moderator:
Upvote 0
I read a lot of books, spent a lot of time trying to speed up work processes, and also learned a lot from trying to answer questions on forums like this one, as well as reviewing other people's solutions to the same questions.
 
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,224
Members
452,620
Latest member
dsubash

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